我有2个核心数据类 - 播放列表和曲目。播放列表可以容纳多个曲目。
以下是我创建曲目并将其添加到播放列表的代码
AppDelegate *del = [[AppDelegate alloc] init];
NSManagedObjectContext *context = del.managedObjectContext;
self.play = cell.obj;
NSLog(@"play %@", self.play);
[Track trackForStorage:self.track inManagedObjectContext:context];
NSError *e2;
[context save:&e2];
if (e2 == nil) {
NSString *entity2 = [NSString stringWithFormat:@"Track"];
NSFetchRequest *fet2 = [NSFetchRequest fetchRequestWithEntityName:entity2];
NSError *e3;
NSArray *array2 = [context executeFetchRequest:fet2 error:&e3];
if ([array2[0] isKindOfClass:[Track class]]) {
Track * t = array2[0];
NSLog(@"track %@", t);
[self.play addTracksObject:t];
}
}
当我尝试将曲目添加到播放列表时,我收到以下错误:
- [播放列表addTracksObject:]:无法识别的选择器发送到实例0x7fd76d911610 2016-04-25 16:27:10.875我的音乐安全[14899:1021546] ***由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [播放列表addTracksObject:]:无法识别的选择器发送到实例0x7fd76d911610'
编辑:这是“播放列表+ CoreDataProperties.h”
@interface Playlist (CoreDataProperties)
@property (nullable, nonatomic, retain) NSString *name;
@property (nullable, nonatomic, retain) NSSet<Track *> *tracks;
@end
@interface Playlist (CoreDataGeneratedAccessors)
- (void)addTracksObject:(Track *)value;
- (void)removeTracksObject:(Track *)value;
- (void)addTracks:(NSSet<Track *> *)values;
- (void)removeTracks:(NSSet<Track *> *)values;
@end
答案 0 :(得分:0)
什么是self.play
?这是没有响应消息-addTracksObject:
是否包含实施文件?
BTW,调用AppDelegate *del = [[AppDelegate alloc] init];
是非常不寻常的,如果您这样做是为了访问NSManagedObjectContext
您将遇到问题。