The code generator for NSManagedObject subclasses in Xcode 7.2- isn't on pair with the code generation for Objective-C. (No accessor methods for to-many relationships.)
So I want to do this:
- Generate NSManagedObject subclasses in Objective-C.
- Create a Bridging header file.
- Write Swift extensions for the generated Objective-C classes.
- Use the extended objective-C classes in Swift.
I do the steps above, but I get a Value of type Person, has no member syHello error, when I try to call the code below.
Objective-C:
@interface Person (CoreDataProperties)
@property (nullable, nonatomic, retain) NSString *name;
@property (nullable, nonatomic, retain) NSSet<Pet *> *pets;
@end
@interface Person (CoreDataGeneratedAccessors)
- (void)addPetsObject:(Pet *)value;
- (void)removePetsObject:(Pet *)value;
- (void)addPets:(NSSet<Pet *> *)values;
- (void)removePets:(NSSet<Pet *> *)values;
@end
Swift:
public extension Person {
public func sayHello() {
print("Hello! My name is \(self.name).")
}
}
Swift:
let myPerson = NSEntityDescription.insertNewObjectForEntityForName("Person", inManagedObjectContext: myAppDelegate.managedObjectContext) as! Person
myPerson.sayHello()
What do I need to do for the compiler to pick upp my extension on my Person class, so that I can call sayHello on it?