简体   繁体   中英

NSMutableArray: count is a method or a property?

I want to verify if I'm in the last cell of the UITable. Should I use a NSInteger property in my controller and store the value of the count of the data (it's an NSMutableArray) that populates the table?

I'm asking because I don't know if count iterates over all objects of the array to count or if it only gets me a value of a count property.

What would be better ?

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

Use the method directly. It is almost certainly efficient enough. If you are having serious performance problems, use shark and instruments to discover why. If you see most of your time is being spent in calls to count, find a way to optimize that, like you suggested here. But don't optimize prematurely like this--you are just wasting your time even thinking about it.

因为表视图的状态可以随时更改,具体取决于iPhone OS在任何给定时间执行的操作,您几乎总是希望从模型中提取状态数据(在本例中为数组)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM