简体   繁体   中英

Has anyone noticed iOS10 NSPersistantContainer. Is it a replacement for NSPersistantStoreCoordinator?

Prior to iOS 10, for initialising a CoreData statck we had 3 major components: NSManagedObjectModel NSPersistantStoreCoordinator NSManagedObjectContext

But in the latest XCode 8 when I created a core data application, I found that there is no NSPersistantStoreCoordinator, instead a new iOS 10 NSPersistantContainer and NSPersistentStoreDescription are seen. Is this going to be a replacement to the existing coredata methods used?

Per the Apple developer docs https://developer.apple.com/reference/coredata/nspersistentcontainer , a persistent container is:

A container that encapsulates the Core Data stack in your application.

NSPersistentContainer simplifies the creation and management of the Core Data stack by handling the creation of the NSManagedObjectModel, NSPersistentStoreCoordinator, and the NSManagedObjectContext.

In short, for iOS10 they've added the persistent container construct to take over the process of creating all of the objects you were required to create in the past. For this one, I'd recommend watching the WWDC video on Core Data from this summer where they went into this in some depth.

For an app that I'd started in advance of Xcode 8 I'm still using the old approach, so you can still build out the persistent store coordinator, etc, but I don't see much point if you're starting something new.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM