如何解决使用NSPredicate匹配整数列表
| 我有一个带有整数字段的表。我想选择该字段包含一些不同值的所有行。 我正在使用这个:[nspredicate predicateWithFormat:@\"myIntValue IN {1,2,3,4}\"]
但这只会返回myIntValue
为1的行。
我究竟做错了什么?
解决方法
这有效:
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSArray *idList = [NSArray arrayWithObjects:[NSNumber numberWithInt:1],[NSNumber numberWithInt:2],[NSNumber numberWithInt:3],[NSNumber numberWithInt:4],nil];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@\"idealForId IN $IDLIST\"];
request.predicate = [predicate predicateWithSubstitutionVariables:
[NSDictionary dictionaryWithObject:idList forKey:@\"IDLIST\"]];
,你有尝试过吗?
NSPredicate *predicate = [NSPredicate predicateWithFormat:@\"myIntValue IN %@\",[NSArray arrayWithObjects:@\"1\",@\"2\",@\"3\",@\"4\",nil]];
该文档可能在这里有用。
,自问题最初发布以来,我不知道这种情况是否已更改,但是我从这三个问题中得到的谓词完全相同。
[NSPredicate predicateWithFormat:@\"myIntValue IN {1,2,3,4}\"];
[NSPredicate predicateWithFormat:@\"myIntValue IN {%d,%d,%d}\",1,4];
[NSPredicate predicateWithFormat:@\"myIntValue IN %@\",@[@1,@2,@3,@4]];
因此,无需将所有内容包装在对象中。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。