Skip to content

Instantly share code, notes, and snippets.

@koromiko
Last active September 7, 2017 02:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koromiko/95dd912dbd495150db1fd35542adbe0c to your computer and use it in GitHub Desktop.
Save koromiko/95dd912dbd495150db1fd35542adbe0c to your computer and use it in GitHub Desktop.
lazy var mockPersistantContainer: NSPersistentContainer = {
let container = NSPersistentContainer(name: "PersistentTodoList", managedObjectModel: self.managedObjectModel)
let description = NSPersistentStoreDescription()
description.type = NSInMemoryStoreType
description.shouldAddStoreAsynchronously = false // Make it simpler in test env
container.persistentStoreDescriptions = [description]
container.loadPersistentStores { (description, error) in
// Check if the data store is in memory
precondition( description.type == NSInMemoryStoreType )
// Check if creating container wrong
if let error = error {
fatalError("Create an in-mem coordinator failed \(error)")
}
}
return container
}()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment