我可以为非 NSString 数据类型匹配 NSPredicate 吗?

she*_*ath 2 objective-c ios

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

@property (strong, nonatomic, readonly) NSUUID *uuid;
Run Code Online (Sandbox Code Playgroud)

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

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

// ..

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"uuid ==[c] %@ ",strUUID];
NSArray *filterArray = [self.arrBeacons filteredArrayUsingPredicate:predicate];
Run Code Online (Sandbox Code Playgroud)

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

小智 5

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

NSPredicate(format: "identifier == %@", uuid as CVarArg)
Run Code Online (Sandbox Code Playgroud)