gpt4 book ai didi

cocoa - 将 NSPredicate 与一组答案结合使用

转载 作者:行者123 更新时间:2023-12-03 16:09:00 25 4
gpt4 key购买 nike

我有一组包含 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)})"'

最佳答案

不要将 zipSet 插入到字符串中,而是将其插入到谓词中:

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

如果将 NSSet 插入到字符串中,它将不会具有正确的格式(NSString 使用 -description,它使用旧的 NextStep property list format )。

关于cocoa - 将 NSPredicate 与一组答案结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4418027/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com