Home Tutorial Iphone Examples NSArray Count Example

 
 

NSArray Count Example
Posted on: October 6, 2010 at 12:00 AM
In the example, we are going to count the number of elements in an array in objective c programming.In Objective C language, Count is a primitive instance method that returns the number of objects available in an array.

NSArray Count Example

In the example, we are going to count the number of elements in an array in objective c programming.

In Objective C language, Count is a primitive instance method that returns the number of objects available in an array.

Syntax of count method in objective c language
- (NSUInteger)count

a simple example:

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];

NSArray *marray;
marray = [NSArray arrayWithObject:@"1"];

int mcount =[marray count];

NSLog (@"array = %i", mcount);

if (mcount == 0)
{
NSLog(@"Array is ZERO");
}
else
{
NSLog(@"Array is ONE");
}
return;

}

the output is:
2010-10-05 15:26:05.700 method[1117:207] array = 1
2010-10-05 15:26:05.728 method[1117:207] Array is ONE

Related Tags for NSArray Count Example:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.