Duplicate Symbol Error in NSManagedObject Subclass

You are generating files which have already been generated for you by Xcode and thus get duplicate declarations. Details about this feature (new in Xcode 8) can be found in this WWDC video. Two possible fixes: 1) Use the Xcode generated ManagedObject subclasses (the recommended, modern approach) Delete all generated NSManagedObject subclasses from your project, … Read more

Swift + CoreData: Cannot Automatically Set Optional Attribute On Generated NSManagedObject Subclass

The optional checkbox in the Core Data Model Editor has been existing before Swift and its optionals where introduced. Apple states about it in its Core Data Programming Guide: You can specify that an attribute is optional — that is, it is not required to have a value. In general, however, you are discouraged from … Read more

How do I copy or move an NSManagedObject from one context to another?

First, having more than one NSManagedObjectContext on a single thread is not a standard configuration. 99% of the time you only need one context and that will solve this situation for you. Why do you feel you need more than one NSManagedObjectContext? Update That is actually one of the few use cases that I have … Read more

How can I duplicate, or copy a Core Data Managed Object?

Here’s a class I created to perform a “deep copy” of managed objects: attributes and relationships. Note that this does not check against loops in the object graph. (Thanks Jaanus for the starting off point…) @interface ManagedObjectCloner : NSObject { } +(NSManagedObject *)clone:(NSManagedObject *)source inContext:(NSManagedObjectContext *)context; @end @implementation ManagedObjectCloner +(NSManagedObject *) clone:(NSManagedObject *)source inContext:(NSManagedObjectContext *)context{ … Read more

Multiple NSEntityDescriptions Claim NSManagedObject Subclass

Post-automatic-caching This should not happen anymore with NSPersistent[CloudKit]Container(name: String), since it seems to cache the model automatically now (Swift 5.1, Xcode11, iOS13/MacOS10.15). Pre-automatic-caching NSPersistentContainer/NSPersistentCloudKitContainer does have two constructors: init(name: String) init(name: String, managedObjectModel model: NSManagedObjectModel) The first is just a convenience initializer calling the second with a model loaded from disk. The trouble is that … Read more

Xcode 8 generates broken NSManagedObject subclasses for iOS 10

I finally got mine to work. Here is what I did. (Flights is one of my entities) I setup the xcdatamodeld as follows And then the entity as Then I used Editor -> Create NSManagedObject Subclass This creates two files for my flights entity Flights+CoreDataProperties.swift Flights+CoreDataClass.swift I renamed Flights+CoreDataClass.swift to Flights.swift Flights.swift is just import … Read more

Changing a managed object property doesn’t trigger NSFetchedResultsController to update the table view

OK, I will explain your problem, then I will let you judge whether it is a bug in FRC or not. If you think it is a bug, then you really should file a bug report with apple. Your fetch result controller predicate is like this: NSString *predicate = [NSString stringWithFormat: @”clockSet.isOpen == YES”]; which … Read more