Created
August 10, 2019 18:44
-
-
Save PaulWoodIII/5cda7c363730fcc591fef708efb49efc to your computer and use it in GitHub Desktop.
used in Xcode test on each unit test, loads fast, is in memory and doesn't affect other test so long as you don't test concurrently
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Just a Holder for a persistentContainer that is lazily loaded | |
class TestPersistentContainer { | |
lazy var persistentContainer: NSPersistentContainer = { | |
let bundle = Bundle(for: CoreDataService.self) | |
let modelURL = bundle.url(forResource: CoreDataModelName, withExtension: "momd")! | |
let mom = NSManagedObjectModel(contentsOf: modelURL)! | |
let container = NSPersistentContainer(name: "LateralModel", | |
managedObjectModel: mom) | |
let description = container.persistentStoreDescriptions.first! | |
description.url = URL(fileURLWithPath: "/dev/null") | |
try! container.persistentStoreCoordinator | |
.destroyPersistentStore(at: URL(fileURLWithPath: "/dev/null"), | |
ofType: NSSQLiteStoreType, | |
options: [:]) | |
container.loadPersistentStores(completionHandler: { (storeDescription, error) in | |
if let error = error as NSError? { | |
fatalError("Unresolved error \(error), \(error.userInfo)") | |
} | |
}) | |
return container | |
}() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment