How to find whether an item is in NSArray or not ?

By | April 6, 2011

Hi,

Sometimes you may need to find/search a particular item in NSArray. How can you find whether a particular item is present in NSArray or not? Look at the code below.

BOOL testFlag= [yourArray containsObject:@"CoderzHeaven"];
if(testFlag) {
	NSLog(@“Yup! It's present!"); }
else {
	NSLog(@"Nopes! It's absent!"); }

Here ‘yourArray is your NSArray and ‘containsObject’ returns either TRUE or FALSE and it get stored in ‘testFlag’.

🙂

Leave a Reply

Your email address will not be published. Required fields are marked *