开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜