title: Setting an NSManagedObject relationship in Swift
body: <p>How does one add an object to a relationship property in an <code>NSManagedObject</code> subclass in Swift?</p>
  
  <p>In Objective-C, when you generate an <code>NSManagedObject</code> subclass in Xcode from the data model, there's an automatically generated class extension which contains declarations like:</p>
  
  <pre><code>@interface MyManagedObject (CoreDataGeneratedAccessors)
  
       - (void)addMySubObject: (MyRelationshipObject *)value;
       - (void)addMySubObjects: (NSSet *)values;
  
  @end
  </code></pre>
  
  <p>However Xcode currently lacks this class generation capability for Swift classes. </p>
  
  <p>If I try and call equivalent methods directly on the Swift object:</p>
  
  <pre><code>myObject.addSubObject(subObject)
  </code></pre>
  
  <p>...I get a compiler error on the method call, because these generated accessors are not visible.</p>
  
  <p>I've declared the relationship property as <code>@NSManaged</code>, as described in the documentation.</p>
  
  <p>Or do I have to revert to Objective-C objects for data models with relationships?</p>