将 NSPredicate 与一组答案结合使用
我有一组包含 personID 的字符串,并且有一个由具有唯一 strPersonID 的人员管理对象组成的 NSFetchedResults。我尝试创建 NSPredicate 但失败了。任何对此的帮助将不胜感激。我对 NSPredicate 有点陌生,所以请友善。
NSSet *zipSet = [NSSet setWithSet:[self getziplist:searchText]];
searchString = [NSString stringWithFormat:@"(strPersonID IN %@)",zipSet];
NSPredicate *searchPersonPredicate = [NSPredicate predicateWithFormat:searchString];
运行时错误消息是:由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“无法解析格式字符串”(strPersonID IN {( 300040, 300082, 412218 )})"'
I have a set of strings containing personIDs and I have a NSFetchedResults of people managedObjects with unique strPersonIDs. I tried to create an NSPredicate but it fails. Any help with this would be greatly appreciated. I'm a bit new to NSPredicate so be kind.
NSSet *zipSet = [NSSet setWithSet:[self getziplist:searchText]];
searchString = [NSString stringWithFormat:@"(strPersonID IN %@)",zipSet];
NSPredicate *searchPersonPredicate = [NSPredicate predicateWithFormat:searchString];
The runtime error message is: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "(strPersonID IN {(
300040,
300082,
412218
)})"'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要将
zipSet
插值到字符串中,而是将其插值到谓词中:如果将 NSSet 插值到字符串中,它将不具有正确的格式(NSString 使用
-description
,它使用旧的 NextStep 属性列表格式)。Don't interpolate
zipSet
into the string, interpolate it into the predicate:If you interpolate the NSSet into a string, it won't have the correct format (NSString uses
-description
, which uses the old NextStep property list format).