So I am really excited to use Core Data now because of how much simpler they made it (as of WWDC 2016).
On app launch, I plan to load pre-updated data from Core Data and then have the persistentContainer
's performBackgroundTask
do updates/saves to some entities. As entities are updated in the background, the UI should always show the most recent data when fetching (whether those entities were updated or not).
When I'm working with ONE context, is it safe to both set the viewContext's automaticallyMergesChangesFromParent
flag to true
AND its generation to .current
?
lazy var persistentContainer: NSPersistentContainer = {
let container: NSPersistentContainer = {
$0.viewContext.automaticallyMergesChangesFromParent = true
try? $0.viewContext.setQueryGenerationFrom(.current)
return $0
}(NSPersistentContainer(name: "MyFirstApp"))
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error {
fatalError("Unresolved error \(error), \(error._userInfo)")
}
})
return container
}()
Thanks!