gpt4 book ai didi

objective-c - 评估 NSArray 上的 NSPredicate(无过滤)

转载 作者:太空狗 更新时间:2023-10-30 03:30:30 25 4
gpt4 key购买 nike

是否可以在 NSArray 上评估 NSPredicate,而不让 NSPredicate 开始过滤掉数组中的对象?

例如,假设我有以下谓词,它只检查数组中对象的数量:

NSPredicate *pred = [NSPredicate predicateWithFormat:@"count == 3"];
NSArray *list = [NSArray arrayWithObjects:@"uno", @"dos", @"volver", nil];
BOOL match = [pred evaluateWithObject:list];

这会崩溃,因为 pred 会尝试从数组中的第一个对象而不是数组本身检索“count”键。

最佳答案

使用NSPredicateSIZE运算符,相当于NSArraycount方法。

NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF[SIZE] == 3"];
NSArray *list = [NSArray arrayWithObjects:@"uno", @"dos", @"volver", nil];
BOOL match = [pred evaluateWithObject:list];

关于objective-c - 评估 NSArray 上的 NSPredicate(无过滤),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7805655/

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