我正在添加从播放列表中删除歌曲 (playlistTrack) 的功能。每个 playlistTrack 都有一个与之关联的 playlist_track_number,因此我们知道歌曲的播放顺序。因此,在删除 playlistTrack 后,我需要分配新的 playlist_track_number 后面的所有 playlistTrack,即比之前的 playlist_track_number 少 1。
我的代码在这里运行良好一次,然后在控制台显示“'Can't do regex matching on object 3”时崩溃。有什么帮助吗?
NSManagedObjectContext *localContext = [NSManagedObjectContext MR_contextForCurrentThread];
NSPredicate *predicateList = [NSPredicate predicateWithFormat:@"(playlist.name CONTAINS[cd] %@)", activePlaylistString];
NSArray *newArray = [[NSArray alloc]init];
newArray = (NSArray*)[Playlist_Track MR_findAllWithPredicate:predicateList];
for (int i = (delTrack + 1); i <= [newArray count]; i++) {
localContext = [NSManagedObjectContext MR_contextForCurrentThread];
NSString *nextTrackNumberString = [NSString stringWithFormat:@"%i",i];
NSPredicate *nextPredicate = [NSPredicate predicateWithFormat:@"(playlist.name CONTAINS[cd] %@) AND (playlist_track_number MATCHES [cd] %@)", activePlaylistString, nextTrackNumberString];
nextTrack = [Playlist_Track MR_findFirstWithPredicate:nextPredicate inContext:localContext];
if (nextTrack) {
int j = i-1;
nextTrack.playlist_track_numberValue = j;
[localContext MR_saveToPersistentStoreWithCompletion:nil];
}
if (!nextTrack) {
//Do Nothing
}
}