I have the following method which is called within a FOR Loop and is called several times, each time iterating through an NSDictionary object to create and set a note object :
- (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;
}
I am trying to optimise this code and have noticed that the findFirstByAttribute method seems to be rather slow. Is there anyway I can optimise this method ?