Skip to content

Commit

Permalink
Fix CoreData test warnings (#1276)
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-livefront authored Jan 16, 2025
1 parent 219e1af commit 0585d04
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions BitwardenShared/Core/Platform/Services/Stores/DataStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ enum StoreType {
/// A data store that manages persisting data across app launches in Core Data.
///
class DataStore {
// MARK: Type Properties

/// The managed object model representing the entities in the database schema. CoreData throws
/// warnings if this is instantiated multiple times (e.g. in tests), which is fixed by making
/// it static.
private static let managedObjectModel: NSManagedObjectModel = {
let modelURL = Bundle(for: DataStore.self).url(forResource: "Bitwarden", withExtension: "momd")!
let managedObjectModel = NSManagedObjectModel(contentsOf: modelURL)!
return managedObjectModel
}()

// MARK: Properties

/// A managed object context which executes on a background queue.
Expand All @@ -45,9 +56,7 @@ class DataStore {
init(errorReporter: ErrorReporter, storeType: StoreType = .persisted) {
self.errorReporter = errorReporter

let modelURL = Bundle(for: type(of: self)).url(forResource: "Bitwarden", withExtension: "momd")!
let managedObjectModel = NSManagedObjectModel(contentsOf: modelURL)!
persistentContainer = NSPersistentContainer(name: "Bitwarden", managedObjectModel: managedObjectModel)
persistentContainer = NSPersistentContainer(name: "Bitwarden", managedObjectModel: Self.managedObjectModel)
let storeDescription: NSPersistentStoreDescription
switch storeType {
case .memory:
Expand Down

0 comments on commit 0585d04

Please sign in to comment.