0

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.

1
  • hi if there in not any array at index 1 then how can we check for that...it will give crash because you are accessing the object which are not present..... Commented Sep 1, 2012 at 9:33

2 Answers 2

1
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");
}
Sign up to request clarification or add additional context in comments.

1 Comment

make this condition for jpg and jpeg also..if u want
0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.