Reputation: 189
if ([pArray objectAtIndex:2]==@"ROOT")
{
NSLog(@"YES");
}
else {
NSLog(@"NO");
}
I am using this code but it's not working
Upvotes: 0
Views: 915
Reputation: 3494
if (([pArray objectAtIndex:2] != (id)[NSNull null])&([[pArray objectAtIndex:2] isEqual:@"ROOT"])){
NSLog(@"String in array is %@",[pArray objectAtIndex:2]);
}
else {
if([pArray objectAtIndex:2] == (id)[NSNull null]){
NSLog(@"Your Object is Null");
}
else{
NSLog(@"Your Object does not match");
}
}
Upvotes: 0
Reputation: 2306
You can use
- (BOOL)containsObject:(id)anObject;
to check if the object is in the array.
eg. [pArray containsObject:@"ROOT"];
if you need to check if particular element is equal to a string you can use.
[[pArray objectAtIndex:2] isEqualToString:@"ROOT"];
Both will return YES if matched.
Upvotes: 1
Reputation: 9367
You must use the isEqualToString method. You are attempting to compare two references in your statement.
if ([[pArray objectAtIndex:2] isEqualToString:@"ROOT"])
Upvotes: 0
Reputation: 22334
Assuming pArray contains strings... use the following...
if([[pArray objectAtIndex:2] isEqualToString:@"ROOT"])
Upvotes: 0
Reputation: 170839
Use isEqualToString: method:
if ([[pArray objectAtIndex:2] isEqualToString:@"ROOT"]){
...
}
Upvotes: 0