Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 689
Ashutosh Avatar asked Apr 25 '11 19:04

Ashutosh


People also ask

What's a difference between NSArray and NSSet?

The main difference is that NSArray is for an ordered collection and NSSet is for an unordered collection. There are several articles out there that talk about the difference in speed between the two, like this one. If you're iterating through an unordered collection, NSSet is great.

Is NSArray ordered?

An object representing a static ordered collection, for use instead of an Array constant in cases that require reference semantics.

Can NSArray contain nil?

arrays can't contain nil.

How do I create an NSArray in Objective C?

Creating an Array Object The NSArray class contains a class method named arrayWithObjects that can be called upon to create a new array object and initialize it with elements. For example: NSArray *myColors; myColors = [NSArray arrayWithObjects: @"Red", @"Green", @"Blue", @"Yellow", nil];


4 Answers

That's really simple:

int arrayLength = array.count;
like image 148
BenB Avatar answered Oct 25 '22 14:10

BenB


[yourNSArrayReference count]; It is simple:=)

like image 23
LuckyLuke Avatar answered Oct 25 '22 14:10

LuckyLuke


Very simple:-

[*your array name* count];
like image 33
Gypsa Avatar answered Oct 25 '22 14:10

Gypsa


you have to just check

[array count];

like image 45
darshan Avatar answered Oct 25 '22 16:10

darshan