0
First of all follow my model:
Classes:
@interface MMEAlbum : NSManagedObject
... outras propriedades
@property (nonatomic, retain) NSNumber *album_upcoming;
@property (nonatomic, retain) NSSet *songs;
@end
--------
@interface MMESong : NSManagedObject
@property (nonatomic, retain) NSNumber *song_id;
@property (nonatomic, retain) NSString *song_name;
@property (nonatomic, retain) MMEAlbum *album;
@end
Populating the bank:
//Parse album
MMEAlbum *newAlbum = [MMEAlbum MR_createInContext:self.managedObjectContext];
newAlbum.album_active = [albumDic active];
newAlbum.album_banner_text = [albumDic banner_text];
... demais propriedades
// Parse Songs
for (NSDictionary *songDic in allSongs)
{
MMESong *newSong = [MMESong MR_createInContext:self.managedObjectContext];
newSong.song_id = [songDic id_song];
newSong.song_name = [songDic name_song];
newSong.album = newAlbum;
}
//Save context
[self saveDefaultContext];
Let’s get to the problem, at some point I need to do a search of a song by name via searchBar
and show the result in a table:
// Esse método é acionado toda vez que uma letra é digitada no teclado
- (NSArray *)searchTracksWith:(NSString *)string
{
NSPredicate *filterTracks = [NSPredicate predicateWithFormat:@"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 very pleasing.
Any idea how to create a NSPredicate
efficient for this type of consultation?