Swift cannot generate dynamic runtime accessors due to strict type system. You can create an extension to Disease
class and add missed methods manually, here is the code:
extension Disease {
func addDogBreedObject(value:DogBreed) {
var items = self.mutableSetValueForKey("dogBreed");
items.addObject(value)
}
func removeDogBreedObject(value:DogBreed) {
var items = self.mutableSetValueForKey("dogBreed");
items.removeObject(value)
}
}
Remarks:
I suggest you to create separate file for extension Disease+CoreData.swift
, This should help to keep your code from overrides when you re-generate the CoreData
model.
It is sufficient to create relationship in one of managed objects, second one will be updated with back reference. (Same as was with Objective-C)
Important: To make it all work you should verify that class names of entities in you CoreData model includes your module name. E.g. MyProjectName.Disease
Answer inspired by: Setting an NSManagedObject relationship in Swift