How to get managedObjectContext for viewController other than getting it from appDelegate?

It is called dependency injection. Basically the caller/constructor should be setting the NSManagedObjectContext onto the called/constructed. In your AppDelegate you should set the NSManagedObjectContext into the rootViewController that is associated with the UIWindow. Your rootViewController should then set the NSManagedObjectContext into the next view controller and so on. How? It is just a simple proper … 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

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

Correct implementation of parent/child NSManagedObjectContext

The parent/child MOC model is a really powerful feature of Core Data. It simplifies incredibly the age-old concurrency problem we used to have to deal with. However, as you’ve stated, concurrency is not your issue. To answer your questions: Traditionally, you use the NSMainQueueConcurrencyType for the NSManagedObjectContext associated with the main thread, and NSPrivateQueueConcurrencyTypes for … Read more

Core Data: Do child contexts ever get permanent objectIDs for newly inserted objects?

It is a known bug, hopefully fixed soon, but in general, obtaining a permanent ID is sufficient, provided you do so before you save the data in the first child, and you only include the inserted objects: [moc obtainPermanentIDsForObjects:moc.insertedObjects.allObjects error:&error] In some complex cases, it is better to get a permanent ID as soon as … 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