For unit tests, I've using something similar to this: https://gist.github.com/aceontech/8860058 to create an in-memory store while testing my core data models. With the introduction of iOS 10, NSPersistentStoreCoordinators are now hidden inside NSPersistentContainers. Has anyone played around with Core Data on iOS 10 and figured out how to initialize something similar? Any help would be appreciated.
Thanks!
You can continue using the old approach. It's not deprecated, and NSPersistentContainer
isn't required.
If you want the newer approach, use the new NSPersistentStoreDescription
class, which handles all the stuff that could be specified when adding a persistent store. You'd do something like
let container = NSPersistentContainer(name: "MyModel")
let description = NSPersistentStoreDescription()
description.type = NSInMemoryStoreType
container.persistentStoreDescriptions = [description]
container.loadPersistentStores(completionHandler: { ...
}
This new class also includes things like automatic lightweight migration options, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With