[英]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.
Button在移至下一个主题时起作用,但是在文件末尾,我的应用程序收到消息obj_fatal并崩溃。 If I knew how many objects there are in my NSArray then the problem will be solved.
如果我知道NSArray中有多少个对象,那么问题将得到解决。 I am getting the details from a .plist file and storing it in to a array.
我从.plist文件中获取详细信息,并将其存储到数组中。
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: 另外,如果您更喜欢属性的外观,则可以执行以下操作,假设您的NSArray称为myArray:
myArray.count
which is the same as @shosti's method, but looks different. 与@shosti的方法相同,但外观不同。
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.
就像我说的那样,两种方式都可以完成相同的事情并调用相同的getter方法。
Hope that helps. 希望能有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.