NSMutableArray: count - method or property?

I want to check if I am in the last UITable cell. Should I use the NSInteger property in my controller and store the amount of data (this is NSMutableArray) that populates the table?

I ask because I don’t know if count will iterate all the objects in the array for counting or if it gets only the value of the count property.

What would be better?

save value: myCount = [myArray count]
use directly: [myArray count]
store numberOfRows: myCount = numberOfRowsInSection: [indexPath 0]
use numberOfRows directly: numberOfRowsInSection: [indexPath 0]

+4
source share
2 answers

Use the method directly. It is almost certainly quite effective. If you have serious performance issues, use the shark and tools to find out why. If you see that most of your time is spent on calls to count, find a way to optimize this, as you suggested here. But do not optimize it prematurely - you are simply wasting your time even thinking about it.

+4
source

Since the state of the table view can change at any time, depending on what the iPhone OS is doing at any given time, you almost always want to pull the state data from your model (from the array in this case).

+2
source

Source: https://habr.com/ru/post/1305217/


All Articles