Reputation: 439
Is there a way to set the maximum index size of an array. For example I have an array of UIImage but I only want the array to store 6 images. How would I set a restriction on that array so it can only hold 6 images
Upvotes: 0
Views: 234
Reputation: 157
Initialize your array with size of 6 and then do any one of the following checks:
Upvotes: 0
Reputation: 11123
There is no such functionality. You would have to implement it yourself:
if array.count < 6 {
array.append(element)
}
or perhaps:
while array.count >= 6 {
array.removeFirst()
}
array.append(element)
Upvotes: 1