jan*_*o42 6 cocoa runtime-error nsset nspredicate
我有一组包含personID的字符串,我有一个NSFetchedResults的人员managedObjects具有唯一的strPersonIDs.我试图创建一个NSPredicate但它失败了.任何有关这方面的帮助将不胜感激.我对NSPredicate有点新意,所以请善待.
NSSet *zipSet = [NSSet setWithSet:[self getziplist:searchText]];
searchString = [NSString stringWithFormat:@"(strPersonID IN %@)",zipSet];
NSPredicate *searchPersonPredicate = [NSPredicate predicateWithFormat:searchString];
Run Code Online (Sandbox Code Playgroud)
运行时错误消息是:由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'无法解析格式字符串"(strPersonID IN {(300040,300082,412218)})"'
不要插入zipSet到字符串中,将其插入到谓词中:
NSSet *zipSet = [NSSet setWithSet:[self getziplist:searchText]];
NSPredicate *searchPersonPredicate = [NSPredicate predicateWithFormat:@"strPersonID IN %@",zipSet];
Run Code Online (Sandbox Code Playgroud)
如果将NSSet插入到字符串中,它将不具有正确的格式(NSString使用-description,它使用旧的NextStep 属性列表格式).