So I have this technique I've found I thought would work to seed a core data db with one I've made. My goal list to take a sqlite database (made with a rough companion app in swiftui), filled with content, that will be part of the application bundle. The goal is to copy that data into the user's core data store and allow them to favorite, make certain changes to the items loaded into the database.
Is this technique I'm trying to use best for read-only databases or could I be implementing this wrong? Or is my best bet to copy over the sqlite once with FileManager?
This is. my persistent container code:
Thank you
Is this technique I'm trying to use best for read-only databases or could I be implementing this wrong? Or is my best bet to copy over the sqlite once with FileManager?
This is. my persistent container code:
Code Block lazy var persistentContainer: NSPersistentContainer = { let container = NSPersistentContainer(name: "UserStore") if isFirstLaunch() { let seededDataURL = Bundle.main.url(forResource: "PopulatedStore", withExtension: "sqlite") if let seededDataURL = seededDataURL { let persistentDescription = NSPersistentStoreDescription(url:seededDataURL) persistentDescription.shouldInferMappingModelAutomatically = true persistentDescription.shouldMigrateStoreAutomatically = true container.persistentStoreDescriptions = [persistentDescription] } } container.loadPersistentStores { (storeDescription, error) in if let error = error { print("error loading persistent store! \(error)") } } return container }()
Thank you