I have 2 core data classes - playlists and tracks. Playlists can hold many tracks.
Here is my code for creating a track and adding it to a playlist
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];
}
}
When I try adding a track to a playlist, i get the following error:
-[Playlist addTracksObject:]: unrecognized selector sent to instance 0x7fd76d911610 2016-04-25 16:27:10.875 My Music Safe[14899:1021546] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Playlist addTracksObject:]: unrecognized selector sent to instance 0x7fd76d911610'
edit: here is the "Playlist+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
Playlist
? It seems like you have aPlaylist
instance, but it really does not have anaddTracksObject:
method. – user212514