我添加了從播放列表中刪除歌曲(playlistTrack)的功能。每個playlistTrack都有一個與它關聯的playlist_track_number,因此我們知道要播放歌曲的順序。因此,在刪除播放列表跟蹤後,我需要分配所有播放列表跟蹤新播放列表_track_number,即比先前playlist_track_number小1。魔法記錄CoreData刪除記錄並重新編號
我的代碼在這裏運行良好,然後崩潰與控制檯顯示「'不能做正則表達式匹配對象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
}
}
您是否認爲這實際上是造成這個問題,或者它只是一個建議作爲最佳實踐? – Fluffhead