jireh
jireh

Reputation: 89

How to Check whether there is any values in NSMutable Array?

I am developing an application, in which I am getting the values from the URL, for example, take it as (demo.png), here what I am doing is, i am separating the string with <componentsSeparatedByString:@"." > and saving that in the array (Index 0 : demo & Index 1: png ). And, it works fine. Now, what i getting struck here, when the value from the URL doesn't contain ".png, .jpeg" then error message is coming. How can i check whether there is a value in ObjectAtIndex:1 is null. What i did for this was,

Coding :

if ([array45 objectAtIndex:1] == NSNULL NULL) {
   NSLog(@"object at index %i has no data", i);
}

Error message:

[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'

Help me with your valuable solutions.

Upvotes: 0

Views: 97

Answers (2)

mad pig
mad pig

Reputation: 788

First you want to find out how many objects are in the array.

int count = [array count];

If you don't have the correct count you don't check what's in an index.

Upvotes: 0

Rajneesh071
Rajneesh071

Reputation: 31081

NSArray *aray = [@"demo.png" componentsSeparatedByString:@"."];

if ([[aray lastObject] isEqualToString:@"png"])
{
    NSLog(@"There is an image with .png");
}
else {
    NSLog(@"There is no image eith .png extension");
}

Upvotes: 1

Related Questions