[Shuffle Function] Rewrite query for Core Data
Rewrite the album filter function to apply the filter predicate against Core Data directly, which also requires filtering out deLeted entries so they don't end up in the results, and also requires sorting the results. Signed-off-by: Christopher Snowhill <kode54@gmail.com>swiftingly
parent
dad2dbf236
commit
9820571a94
|
@ -1108,12 +1108,28 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc
|
|||
}
|
||||
|
||||
- (NSArray *)filterPlaylistOnAlbum:(NSString *)album {
|
||||
NSPredicate *predicate;
|
||||
NSPredicate *deletedPredicate = [NSPredicate predicateWithFormat:@"deLeted == NO || deLeted == nil"];
|
||||
|
||||
NSPredicate *searchPredicate;
|
||||
if([album length] > 0)
|
||||
predicate = [NSPredicate predicateWithFormat:@"album like %@", album];
|
||||
searchPredicate = [NSPredicate predicateWithFormat:@"album like %@", album];
|
||||
else
|
||||
predicate = [NSPredicate predicateWithFormat:@"album == nil || album like %@", @""];
|
||||
return [[self arrangedObjects] filteredArrayUsingPredicate:predicate];
|
||||
searchPredicate = [NSPredicate predicateWithFormat:@"album == nil || album like %@", @""];
|
||||
|
||||
NSCompoundPredicate *predicate = [NSCompoundPredicate andPredicateWithSubpredicates:@[deletedPredicate, searchPredicate]];
|
||||
|
||||
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"PlaylistEntry"];
|
||||
request.predicate = predicate;
|
||||
|
||||
NSError *error = nil;
|
||||
NSArray *results = [self.persistentContainer.viewContext executeFetchRequest:request error:&error];
|
||||
|
||||
if(results && [results count] > 0) {
|
||||
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"index" ascending:YES];
|
||||
results = [results sortedArrayUsingDescriptors:@[sortDescriptor]];
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
- (PlaylistEntry *)getPrevEntry:(PlaylistEntry *)pe {
|
||||
|
|
Loading…
Reference in New Issue