OGeek|极客世界-中国程序员成长平台

标题: ios - 我可以为非 NSString 数据类型匹配 NSPredicate 吗? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 09:49
标题: ios - 我可以为非 NSString 数据类型匹配 NSPredicate 吗?

在我的模型类 (Beacon.h) 中,我有这个属性

@property (strong, nonatomic, readonly) NSUUID *uuid;

我有一个包含该 Beacon 类的对象的数组,我想使用 NSPredicate 对其进行过滤。如果 uuid 类型是字符串,它可以工作:

@property (strong, nonatomic, readonly) NSString *uuid;

// ..

NSPredicate *predicate = [NSPredicate predicateWithFormat"uuid ==[c] %@ ",strUUID];
NSArray *filterArray = [self.arrBeacons filteredArrayUsingPredicate:predicate];

当 uuid 属性是 NSUUID(不是 NSString)时,我如何编写 NSPredicate。



Best Answer-推荐答案


用于匹配 UUID 的 Swift 样式谓词,其中 identifier 是您的 UUID 属性的名称(适用于 Core Data):

NSPredicate(format: "identifier == %@", uuid as CVarArg)

关于ios - 我可以为非 NSString 数据类型匹配 NSPredicate 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26860010/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4