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 {
|
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()
|
private(set) lazy var backgroundContext = newBackgroundContext()
|
||||||
|
|
||||||
let statusSubject = PassthroughSubject<String, Never>()
|
let statusSubject = PassthroughSubject<String, Never>()
|
||||||
let accountSubject = PassthroughSubject<String, Never>()
|
let accountSubject = PassthroughSubject<String, Never>()
|
||||||
|
|
||||||
init(for controller: MastodonController) {
|
init(for controller: MastodonController) {
|
||||||
let url = Bundle.main.url(forResource: "Tusker", withExtension: "momd")!
|
super.init(name: "\(controller.accountInfo!.id)_cache", managedObjectModel: MastodonCachePersistentStore.managedObjectModel)
|
||||||
let model = NSManagedObjectModel(contentsOf: url)!
|
|
||||||
super.init(name: "\(controller.accountInfo!.id)_cache", managedObjectModel: model)
|
|
||||||
loadPersistentStores { (description, error) in
|
loadPersistentStores { (description, error) in
|
||||||
if let error = error {
|
if let error = error {
|
||||||
fatalError("Unable to load persistent store: \(error)")
|
fatalError("Unable to load persistent store: \(error)")
|
||||||
|
|
Loading…
Reference in New Issue