0

我到底在这里做错了什么?沮丧到难以置信。

我有一个数组,其中包含具有属性的某种类型的对象。我们只称该属性为“数字”。它是类型NSUInteger

我还有一个实体,其属性为“数字”,类型为Integer 64.

我正在尝试创建一个获取请求,该请求可以找到我的核心数据存储中的所有对象,这些对象在另一个包含对象的数组中存在。

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
fetchRequest.entity = [NSEntityDescription entityForName:@"EntityName" inManagedObjectContext:context];
fetchRequest.predicate = [NSPredicate predicateWithFormat:@"NOT (%@.number IN number)",someArrayWithObjects];
NSError *error = nil;
NSArray *notMatchingObjects = [context executeFetchRequest:fetchRequest error:&error];

这将返回一个 nil 数组。我知道我的本地商店中有带有数字的对象,这些对象在我的其他数组中不存在。难道我做错了什么?

4

2 回答 2

1

使用 NSArrays 符合键值编码的事实,并将为您提供一个属性值数组valueForKey:(对于 NSUInteger,它会将它们包装在 NSNumbers 中)

NSArray *predicateInts = [someArrayWithObjects valueForKey:@"number"];
[NSPredicate predicateWithFormat:@"NOT (number IN %@)",predicateInts];
于 2012-09-09T02:28:24.560 回答
0

首先,您必须创建一个NSNumber仅包含要排除的数字的对象数组。

然后您可以使用以下获取请求:

[NSPredicate predicateWithFormat:@"NOT (number IN %@)", arrayWithNumbers];
于 2012-09-09T02:27:12.703 回答