NSArray Count Example


 

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.

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

Ads