我写了一个方法如下
-(NSArray*)getClubDetailedDeals:(NSString *)clubID{
NSError *error;
NSManagedObjectContext *context = [self managedObjectContext];
NSFetchRequest * fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"ClubDetailsDeals"
inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSArray *fetchedArray1 = [[context executeFetchRequest:fetchRequest error:&error] mutableCopy];
ClubDetailsDealsDAO *obb = [fetchedArray1 objectAtIndex:0];
NSLog(@"MY ID IS %@ and count is %d", obb.dealname, [fetchedArray1 count]);
NSLog(@"deal is %@", clubID);
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(%K CONTAINS %@)", @"clubid", clubID];
//NSPredicate *predicate = [NSPredicate predicateWithFormat:@"dealid contains[cd] %@", dealID];
[fetchRequest setPredicate:predicate];
NSArray *fetchedArray = [[context executeFetchRequest:fetchRequest error:&error] mutableCopy];
NSLog(@"COUNT of arary is ~~~~ %d", [fetchedArray count]);
return fetchedArray;
}
这里,这个LOG中的Array个数是
* NSLog(@"MY ID IS %@ and count is %d", obb.dealname, [fetchedArray1 count]);*
显示不止一个元素,随着我添加的更多,它会适当增加。
但是当我使用这个查询来获取它时
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(%K CONTAINS %@)", @"clubid", clubID];
它什么也不返回,即使是 OBJECT 在 CoreData 中也可用。
那么通过匹配俱乐部ID(即NSString)获取的正确查询是什么?