使用NSPredicate与一组答案 [英] using NSPredicate with a set of answers

查看:100
本文介绍了使用NSPredicate与一组答案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组包含personIDs的字符串,我有一个NSFetchedResults的人managedObjects与唯一的strPersonIDs。我试图创建一个NSPredicate,但它失败。任何帮助,这将非常感谢。我对NSPredicate有点陌生,所以要亲切。

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];

运行时错误消息是:由于未捕获异常而终止应用程序NSInvalidArgumentException,原因:无法解析格式字符串(strPersonID IN {(
300040,
300082,
412218
)})'

The runtime error message is: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "(strPersonID IN {( 300040, 300082, 412218 )})"'

推荐答案

不要在字符串中插入 zipSet ,将其插入谓词:

Don't interpolate zipSet into the string, interpolate it into the predicate:

NSSet *zipSet = [NSSet setWithSet:[self getziplist:searchText]];
NSPredicate *searchPersonPredicate = [NSPredicate predicateWithFormat:@"strPersonID IN %@",zipSet];

如果将NSSet内插到字符串,它将不具有正确的格式(NSString uses -description ,它使用旧的NextStep 属性列表格式)。

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).

这篇关于使用NSPredicate与一组答案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆