diff --git a/Tusker/CoreData/MastodonCachePersistentStore.swift b/Tusker/CoreData/MastodonCachePersistentStore.swift index 4807201dec..b437deda58 100644 --- a/Tusker/CoreData/MastodonCachePersistentStore.swift +++ b/Tusker/CoreData/MastodonCachePersistentStore.swift @@ -13,15 +13,18 @@ import Combine class MastodonCachePersistentStore: NSPersistentContainer { + private static let managedObjectModel: NSManagedObjectModel = { + let url = Bundle.main.url(forResource: "Tusker", withExtension: "momd")! + return NSManagedObjectModel(contentsOf: url)! + }() + private(set) lazy var backgroundContext = newBackgroundContext() let statusSubject = PassthroughSubject() let accountSubject = PassthroughSubject() init(for controller: MastodonController) { - let url = Bundle.main.url(forResource: "Tusker", withExtension: "momd")! - let model = NSManagedObjectModel(contentsOf: url)! - super.init(name: "\(controller.accountInfo!.id)_cache", managedObjectModel: model) + super.init(name: "\(controller.accountInfo!.id)_cache", managedObjectModel: MastodonCachePersistentStore.managedObjectModel) loadPersistentStores { (description, error) in if let error = error { fatalError("Unable to load persistent store: \(error)")