简体   繁体   中英

Determining the number of objects in an NSArray

I am making a book application. To move to the next topic I am using a button. The Button works as it moves to the next topic, but at the end of the file my application gets the message obj_fatal and it crashes. If I knew how many objects there are in my NSArray then the problem will be solved. I am getting the details from a .plist file and storing it in to a array.

So if any one knows how, please let me know.

Thanks in advance. Viral.

-[NSArray count]

Alternatively, if you prefer the look and feel of a property, you can do the following, assuming your NSArray is called myArray:

myArray.count

which is the same as @shosti's method, but looks different.

The difference is readability. So you could have:

if ([myArray count] > 0)

or you could have

if (myArray.count > 0)

which probably looks neater.

Both answers are good and correct. Whichever you choose depends on your coding style. As I said, both ways accomplish the same thing and call the same getter method.

Hope that helps.

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