Reputation: 557
So this is probably really simple but for some reason I can't figure it out. When I run the below code I can't get it to go into the if
statement even though when I go into the debugger console in xcode and I execute po [resultObject valueForKey:@"type"]
it returns 0
. What am I doing wrong? Thanks for your help!
NSManagedObject *resultObject = [qResult objectAtIndex:i];
if (([resultObject valueForKey:@"type"])== 0) {
//do something
}
Upvotes: 1
Views: 3849
Reputation: 237010
The result of valueForKey:
is always an object — and the only object equal to 0 is nil. In the case of a numerical value, it will be an NSNumber. At any rate, I think you want to ask for [[resultObject valueForKey:@"type"] intValue]
.
Upvotes: 8
Reputation: 5820
You could try casting the NSManagedObject to an int (if thats what it actually is...)
Also you don't need the extra parentheses around the [ ]
NSManagedObject *resultObject = [qResult objectAtIndex:i];
if ((int)[resultObject valueForKey:@"type"] == 0) {
//do something
}
Upvotes: 0