forked from shadowfacts/Tusker
Only initialize NSManagedObjectModel once
Prevents CoreData warnings when switching accounts and constructing a second MastodonCachePersistentStore
This commit is contained in:
parent
866edc472d
commit
b220948e2b
|
@ -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<String, Never>()
|
||||
let accountSubject = PassthroughSubject<String, Never>()
|
||||
|
||||
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)")
|
||||
|
|
Loading…
Reference in New Issue