私はこの方法を使用していますが、正しくありません。
- (BOOL)checkExistByEntityName:(NSString *)entityName primaryKeyName:(NSString *)keyName primaryKey:(NSNumber *)primaryKey
{
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:entityName inManagedObjectContext:managedObjectContext];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%@==%@", keyName, primaryKey];
[request setEntity:entity];
[request setPredicate:predicate];
NSError *error = nil;
NSInteger count = [managedObjectContext countForFetchRequest:request error:&error];
[request release];
if (count > 0) {
return YES;
} else {
return NO;
}
}