swift2 - How do I save an entity into another entity core data swift -


so have users entity , hobby entity, have created relationship of to-many 1 user can have many hobbies. have created inverse relationship well. have generated subclasses entities not sure how save hobby entity user entity.

here user subclasses:

import foundation import coredata  class users: nsmanagedobject { // insert code here add functionality managed object subclass  }  import foundation import coredata  extension users {      @nsmanaged var password: string?     @nsmanaged var username: string?     @nsmanaged var hobby: nsset?  } 

here hobby subclasses:

import foundation import coredata  class hobby: nsmanagedobject {  // insert code here add functionality managed object subclass  }  import foundation import coredata  extension hobby {      @nsmanaged var name: string?  } 

i have figured out how add/update/delete items core data not sure how add whole entity another. great! if doing wrong or thinking wrong way please correct me also.

first need create subclasses in example relationship many. subclass (teacher/course+coredataproperties.swift) looks this:

import foundation import coredata  extension teacher {  @nsmanaged var name: string? @nsmanaged var lastname: string? @nsmanaged var course: nsset?  } 

and this:

import foundation import coredata  extension course {  @nsmanaged var name: string? @nsmanaged var teacher: teacher?  } 

after when create teacher object or fetch existing one, , create or fetch course object can access course property "teacher" , set (let‘s new course math):

math.teacher = (here add teacher object math course related too) 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -