I have an SearchStringTooltip
ManagedObject. With property @dynamic tooltipText;
(NSString)
I need to dynamically add new tooltips in database, but I need only unique values (insensitive).
They could come in more than 100 per one time; and every time I check for unique..
It looks like:
if (newTooltips.count == 0)
return;
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"SearchStringTooltip"
inManagedObjectContext:self.moc];
NSFetchRequest *request = [NSFetchRequest new];
[request setEntity:entity];
for (NSString *name in newTooltips) {
[request setPredicate:[NSPredicate predicateWithFormat:@"tooltipText = %@", name]]; //like = (=) + time *2(sometimes *3) ofcourse i know i need like.. Its insensitive
NSInteger count = [self.moc countForFetchRequest:request error:nil]; //But its is very expensive operation expensive
if (count > 0) {
continue;
}
DBSearchStringTooltip *tooltip = [NSEntityDescription insertNewObjectForEntityForName:@"SearchStringTooltip"
inManagedObjectContext:self.moc];
tooltip.tooltipText = name;
}
How can I do it more cheaply for memory? There can be > 10 000 tooltips for check unique... And I have to check them all.