使用NSPredicate和ID数组过滤数组

Jet*_*ack 1 arrays objective-c nspredicate

我正在尝试使用过滤字典对象数组NSPredicate。我有一个Id数组,我想对此数组进行过滤,但是我不确定如何执行此操作。这是我最接近工作版本的版本。但是NSPredicate,当它作为NSString指南时,它以为Self.id是一个数字

NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"SELF.id CONTAINS %@", UserIds];
Run Code Online (Sandbox Code Playgroud)

但是,此错误与以下内容有关:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't look for value ((
"36eaec5a-00e7-4b10-b78e-46f7396a911b",
"26fc5ea2-a14b-4535-94e9-6fb3d113838c",
"0758a7d0-0470-4ff6-a96a-a685526bccbb",
"10dae681-a444-469c-840d-0f16a7fb0871",
"0280234c-36ae-4d5f-994f-d6ed9eff6b62",
"89F1D9D4-09E2-41D3-A961-88C49313CFB4"
)) in string (1f485409-9fca-4f2e-8ed2-f54914e6702a); value is not a string '
Run Code Online (Sandbox Code Playgroud)

您可以提供的任何帮助都会很棒。

jpe*_*erl 5

您将要用来IN比较到的值SELF.id与数组值,而不是CONTAINS进行字符串匹配的。

解:

NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"SELF.id IN %@", UserIds];