NSPredicate与64位整数?

时间:2011-03-25 03:04:47

标签: objective-c xcode

我正在尝试将NSPredicate与64位数字一起使用,但由于某种原因它失败了。我用以下字符串创建一个谓词:

[NSString stringWithFormat:@"UID == %qu", theUID]

它总是失败。然而,如果我遍历我的对象并比较if ( UID == theUID ),我发现一个很好。我真的很困惑为什么这不能正常工作。

以上看起来是否正确?我的谓词适用于其他整数甚至字符串。但这似乎失败了。

谢谢!

编辑:太奇怪......所以我通过以下方式创建谓词:

NSPredicate *myPredicate = [NSPredicate predicateWithFormat:myString];

现在,当我打印myString,然后打印myPredicate(通过执行NSLog(@"%@", blah);)时,我得到:

  

字符串:UID == 17667815990388404861谓词:UID ==   9223372036854775807

这是相同的字符串,为什么这些不同?

2 个答案:

答案 0 :(得分:2)

可能UID不是无符号值?

构建谓词的更健壮的方法是传入NSNumber:

NSNumber *theUIDNum = [NSNumber numberWithUnsignedLongLong:theUID];
[NSString stringWithFormat:@"UID == %@", theUID]

这为您提供了调试和打印出UINum值以确保其转换正确的奖励功能。

答案 1 :(得分:0)

在您的NSPredicate中,您可以使用类似的

let myNSNumber = NSNumber(value: theUID)
let predicate = NSPredicate(format: "UID = %i", myNSNumber.int64Value)
相关问题