0

我正在使用这段代码从核心数据中获取一些东西:

NSFetchRequest *req = [[NSFetchRequest alloc] initWithEntityName:@"Friend"];

NSString *predicateString = [NSString stringWithFormat:
                             @"identifier == %@", [[friendInfo objectForKey:@"id"] stringFromMD5]];
NSPredicate *predicate = [NSPredicate predicateWithFormat:predicateString];
req.predicate = predicate;

req.fetchLimit = 1;
NSError *requestError = nil;
NSArray *tmp = [self.managedObjectContext executeFetchRequest:req error:&requestError];

但它崩溃了

NSString *predicateString = [NSString stringWithFormat:
                                 @"identifier == %@", [[friendInfo objectForKey:@"id"] stringFromMD5]];

如果我删除 stringFromMD5 方法调用,它可以工作。

NSString *predicateString = [NSString stringWithFormat:
                                     @"identifier == %@", [friendInfo objectForKey:@"id"]];

知道为什么吗?谢谢

4

1 回答 1

2

请尝试以下方法,它可能会很好用:

NSPredicate *_predicate = [NSPredicate predicateWithFormat:@"%K == %@", @"identifier", [[friendInfo objectForKey:@"id"] stringFromMD5]];
于 2012-07-20T13:16:29.797 回答