Share on Google+Share on Google+

NSArray Count Example

Advertisement
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

Advertisements

Advertisement

Posted on: October 6, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.