Reputation: 6008
I'm trying to use NSPredicate with 64-bit numbers, but for some reason it's failing. I create a predicate with the following string:
[NSString stringWithFormat:@"UID == %qu", theUID]
And it always fails. Yet if I loop through my objects and compare if ( UID == theUID )
I find one that is fine. I'm really confused as to why this isn't working correctly.
Does the above look correct? My predicates work fine for other integers or even strings. But this seems to be failing.
Thanks!
Edit: So strange... so I create my predicate by doing:
NSPredicate *myPredicate = [NSPredicate predicateWithFormat:myString];
Now when I print myString, and then print myPredicate (by doing NSLog(@"%@", blah);
) I get:
String: UID == 17667815990388404861 Predicate: UID == 9223372036854775807
It's the same string, why are these different?
Upvotes: 1
Views: 1598
Reputation: 432
In your NSPredicate
you can use something like this
let myNSNumber = NSNumber(value: theUID)
let predicate = NSPredicate(format: "UID = %i", myNSNumber.int64Value)
Upvotes: 1
Reputation: 75058
Possibly theUID is not an unsigned value?
A more robust way to build predicates would be to pass in an NSNumber:
NSNumber *theUIDNum = [NSNumber numberWithUnsignedLongLong:theUID];
[NSString stringWithFormat:@"UID == %@", theUID]
This gives you the bonus ability to debug and print out the value of theUINum to make sure it got the transition right.
Upvotes: 2