ios - Saving data into a One-to-many CoreData relationship in Swift -


so have 2 core data entities. listing , comment. listing can have multiple comments ive created one-to-many relationship between them.

extension listing {      @nsmanaged var listingtitle: string?     @nsmanaged var comments: nsset? }  extension comment {      @nsmanaged var comment: string?     @nsmanaged var commentid: string?     @nsmanaged var rating: int32     @nsmanaged var username: string?     @nsmanaged var listing: listing?  } 

however, cant seem figure out how add comment listing?

i data json blobs , parse values it, i'd have this:

let comment = nsentitydescription.insertnewobjectforentityforname("comment", inmanagedobjectcontext: moc) as! comment  comment.username = "user1" 

but how assign comment pre-defined listing?

hope made sense. thank you!

comment has to-one relationship listing. set relationship.

newcomment.listing = listing 

Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -