時間プロファイル テンプレートに対してアプリのプロファイルを作成しましたが、 によって実行される処理が、executeFetchRequest:error:
複数回行われ、コアデータの多くのレコードに向かって行われるため、膨大な時間を消費していることに気付きました。
-(Customer *) getCustomerByName:(NSString *)_name
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name like %@",_name];
NSFetchRequest *fetchReq = [[NSFetchRequest alloc] init];
[fetchReq setPredicate:predicate];
[fetchReq setEntity:[NSEntityDescription entityForName:@"customer" inManagedObjectContext:self.managedObjectContext]];
NSArray *all = [self.managedObjectContext executeFetchRequest:fetchReq error:nil];
if ([all count] > 0) {
return (Customer*)[all objectAtIndex:0];
}
return nil;
}
上記のメソッドの呼び出しは複数回行われ、約 2000 回の呼び出しが行われていることが確認できます。そのためexecuteFetchRequest:error:
、顧客が存在するかどうかを確認するために、コアデータ内の膨大な数のレコードを毎回取得しています。executeFetchRequest:error:
消費時間を短縮するために処理を変更する方法はありますか? 何かご意見は?
ありがとう。