First of all, follow my model:
Classes:
@interfaceMMEAlbum:NSManagedObject...outraspropriedades@property(nonatomic,retain)NSNumber*album_upcoming;@property(nonatomic,retain)NSSet*songs;@end--------@interfaceMMESong:NSManagedObject@property(nonatomic,retain)NSNumber*song_id;@property(nonatomic,retain)NSString*song_name;@property(nonatomic,retain)MMEAlbum*album;@end
Populatingthebank:
//ParsealbumMMEAlbum*newAlbum=[MMEAlbumMR_createInContext:self.managedObjectContext];newAlbum.album_active=[albumDicactive];newAlbum.album_banner_text=[albumDicbanner_text];...demaispropriedades//ParseSongsfor(NSDictionary*songDicinallSongs){MMESong*newSong=[MMESongMR_createInContext:self.managedObjectContext];newSong.song_id=[songDicid_song];newSong.song_name=[songDicname_song];newSong.album=newAlbum;}//Savecontext[selfsaveDefaultContext];
Let'sgototheproblem,atsomepointIneedtosearchforasongbynameviasearchBar
andshowtheresultinatable:
//Essemétodoéacionadotodavezqueumaletraédigitadanoteclado-(NSArray*)searchTracksWith:(NSString*)string{NSPredicate*filterTracks=[NSPredicatepredicateWithFormat:@"song_name contains[c] %@", string];
NSArray *result = [MMESong MR_findAllWithPredicate:filterTracks];
return result;
}
I have 80,000 (eighty thousand) songs registered in the bank and when I perform the search using the above predicate besides being slow it freezes my view.
I tried to use this other predicate by searching through the parent root:
NSPredicate *filterTracks = [NSPredicate predicateWithFormat:@"ANY songs.song_name contains[c] %@", string];
NSArray *result = [MMEAlbum MR_findAllWithPredicate:filterTracks];
return result;
Improved response time, but nothing to please.
Any idea how to create a NSPredicate
that is efficient for this type of query?