Core Data simple relationship in code

后端 未结 1 1703
猫巷女王i
猫巷女王i 2021-02-06 17:42

I am a cocoa newbie trying to create an iPhone app including Core Data.

My problem is this: I have a little app running now with a single entity called Playlist that I d

1条回答
  •  醉酒成梦
    2021-02-06 18:23

    Petter,

    There should be a method on the PlayList model object that is something like:

    - (void) addSongObject:(Song *)value;
    

    It is a dynamically generated method that will insert a Song value into the relationship for songs in PlayList. If you have not generated the PlayList model object since adding the Song relationship, that method will not be there. So, make sure you generate model classes for any changed entities.

    The Song object that you pass to the addSongObject method should be created using the ManagedObjectContext like:

    Song *song = (Song *)[NSEntityDescription insertNewObjectForEntityForName:@"Song" inManagedObjectContext:playlistListManagedObjectContext];
    

    Jack

    0 讨论(0)
提交回复
热议问题