简体   繁体   中英

How to count the number of items in a NSArray?

I want to count the number of items in a NSArray and perform some operation based on that. I know it's not a big deal but I couldn't get it.

Please give some suggestions.

这很简单:

int arrayLength = array.count;

[yourNSArrayReference count] ; It is simple:=)

很简单:-

[*your array name* count];

you have to just check

[array count];

Make sure you declared your value as the correct type or else you will get: Implicit conversion of 'int' to 'x' is disallowed with ARC .

You could this...

num = [yourArray count];

and you'll get Implicit conversion loses integer precision: 'NSUInteger' (aka 'unsigned long') to 'int'

So then you should do this:

num = (int)[allValues count];

Or:

num = (int)allValues.count;

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