FORループ内で呼び出され、NSDictionaryオブジェクトを反復してノートオブジェクトを作成および設定するたびに数回呼び出される次のメソッドがあります。
- (BOOL)updateById:(NSString *)entityId
withData:(NSDictionary *)dataDictionary {
DLog(@"Updating %@", [_entityClass description]);
if (_entityIdentifier == nil) {
DLog(@"entityIdentifier has not been set");
}
NSManagedObjectContext *context = ContextForThread;
id note = [_entityClass findFirstByAttribute:_entityIdentifier
withValue:entityId
inContext:context]; //This is running slowly ?
[note setValuesFromDictionary:dataDictionary];
BOOL changes = YES;
if ([note changedValues].count == 0) {
changes = NO;
DLog(@"Has NOT changed - Dont save");
}
else {
DLog(@"Has changed");
}
return changes;
}
このコードを最適化しようとしていますが、findFirstByAttribute メソッドがかなり遅いようです。この方法を最適化できる方法はありますか?