V.V
V.V

Reputation: 3094

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.

Upvotes: 0

Views: 419

Answers (2)

BigSauce
BigSauce

Reputation: 1840

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.

Upvotes: 0

shosti
shosti

Reputation: 7422

-[NSArray count]

Upvotes: 4

Related Questions