I was successfully learning SwiftData on the Simulator after following Paul's guide on seeding a database here: https://www.hackingwithswift.com/quick-start/swiftdata/how-to-pre-populate-an-app-with-an-existing-swiftdata-database
My code is as follows in ContentView.swift
import SwiftUI
import SwiftData
@main
struct SomeApp: App {
let container: ModelContainer
var body: some Scene {
WindowGroup {
ContentView()
}
.modelContainer(container)
}
init() {
do {
guard let storeURL = Bundle.main.url(forResource: "Galaxy", withExtension: "store") else {
fatalError("Failed to find store")
}
let config = ModelConfiguration(url: storeURL)
container = try ModelContainer(for: Galaxy.self, configurations: config)
} catch {
fatalError("Failed to create model container: \(error)")
}
}
}
Below is the error I receive when running on a physical device. It works just fine on the Simulator. I think it makes sense given how strict Apple is our file system permissions, I just can't figure out the error... to be clear, I don't want it to be in read only mode....
I think this is the important line:
NSUnderlyingException=error during SQL execution : attempt to write a readonly database, reason=error during SQL execution : attempt to write a readonly database}
THANKS IN ADVANCE!
CoreData: error: Executing as effective user 501
CoreData: error: Information for /private/var/containers/Bundle/Application/9D5150DC-82DD-4220-9898-7438EBA362B3/SomeApp.app/Galaxy.store
CoreData: error: ---------------------------
CoreData: error: File Device ID: 0
CoreData: error: Device ID: 16777225
CoreData: error: File Size: 700416 bytes
CoreData: error: File inode: 808653
CoreData: error: File user ID: 33
CoreData: error: File group ID: 33
CoreData: error: File Permissions:
CoreData: error: -
CoreData: error: 644
CoreData: error: file is not a symbolic link
CoreData: error: Information for file system
CoreData: error: ---------------------------
CoreData: error: File system type: 0x1a
CoreData: error: File system flags: 0x14809098
CoreData: error: MNT_JOURNALED
CoreData: error: Total data blocks: 31215429
CoreData: error: Free data blocks: 10239230
CoreData: error: Free blocks for nonsuperuser: 10239230
CoreData: error: Total i-nodes: 409733646
CoreData: error: File system ID: 0x1000009, 0x1a
CoreData: error: Free i-nodes: 409569200
CoreData: error: Owner UID: 0
CoreData: error: Filesystem type name: apfs
CoreData: error: Mount on name: /private/var
CoreData: error: Mount from name: /dev/disk1s2
CoreData: fault: Attempt to add read-only file at path file:///private/var/containers/Bundle/Application/9D5150DC-82DD-4220-9898-7438EBA362B3/SomeApp.app/Galaxy.store read/write. Adding it read-only instead. This will be a hard error in the future; you must specify the NSReadOnlyPersistentStoreOption.
CoreData: error: Executing as effective user 501
CoreData: error: Information for /private/var/containers/Bundle/Application/9D5150DC-82DD-4220-9898-7438EBA362B3/SomeApp.app/Galaxy.store
CoreData: error: ---------------------------
CoreData: error: File Device ID: 0
CoreData: error: Device ID: 16777225
CoreData: error: File Size: 700416 bytes
CoreData: error: File inode: 808653
CoreData: error: File user ID: 33
CoreData: error: File group ID: 33
CoreData: error: File Permissions:
CoreData: error: -
CoreData: error: 644
CoreData: error: file is not a symbolic link
CoreData: error: Information for file system
CoreData: error: ---------------------------
CoreData: error: File system type: 0x1a
CoreData: error: File system flags: 0x14809098
CoreData: error: MNT_JOURNALED
CoreData: error: Total data blocks: 31215429
CoreData: error: Free data blocks: 10239230
CoreData: error: Free blocks for nonsuperuser: 10239230
CoreData: error: Total i-nodes: 409733646
CoreData: error: File system ID: 0x1000009, 0x1a
CoreData: error: Free i-nodes: 409569200
CoreData: error: Owner UID: 0
CoreData: error: Filesystem type name: apfs
CoreData: error: Mount on name: /private/var
CoreData: error: Mount from name: /dev/disk1s2
CoreData: error: Executing as effective user 501
CoreData: error: Information for /private/var/containers/Bundle/Application/9D5150DC-82DD-4220-9898-7438EBA362B3/SomeApp.app/Galaxy.store
CoreData: error: ---------------------------
CoreData: error: File Device ID: 0
CoreData: error: Device ID: 16777225
CoreData: error: File Size: 700416 bytes
CoreData: error: File inode: 808653
CoreData: error: File user ID: 33
CoreData: error: File group ID: 33
CoreData: error: File Permissions:
CoreData: error: -
CoreData: error: 644
CoreData: error: file is not a symbolic link
CoreData: error: Information for file system
CoreData: error: ---------------------------
CoreData: error: File system type: 0x1a
CoreData: error: File system flags: 0x14809098
CoreData: error: MNT_JOURNALED
CoreData: error: Total data blocks: 31215429
CoreData: error: Free data blocks: 10239230
CoreData: error: Free blocks for nonsuperuser: 10239230
CoreData: error: Total i-nodes: 409733646
CoreData: error: File system ID: 0x1000009, 0x1a
CoreData: error: Free i-nodes: 409569200
CoreData: error: Owner UID: 0
CoreData: error: Filesystem type name: apfs
CoreData: error: Mount on name: /private/var
CoreData: error: Mount from name: /dev/disk1s2
error: Executing as effective user 501
error: Information for /private/var/containers/Bundle/Application/9D5150DC-82DD-4220-9898-7438EBA362B3/SomeApp.app/Galaxy.store
error: ---------------------------
error: File Device ID: 0
error: Device ID: 16777225
error: File Size: 700416 bytes
error: File inode: 808653
error: File user ID: 33
error: File group ID: 33
error: File Permissions:
error: -
error: 644
error: file is not a symbolic link
error: Information for file system
error: ---------------------------
error: File system type: 0x1a
error: File system flags: 0x14809098
error: MNT_JOURNALED
error: Total data blocks: 31215429
error: Free data blocks: 10239230
error: Free blocks for nonsuperuser: 10239230
error: Total i-nodes: 409733646
error: File system ID: 0x1000009, 0x1a
error: Free i-nodes: 409569200
error: Owner UID: 0
error: Filesystem type name: apfs
error: Mount on name: /private/var
error: Mount from name: /dev/disk1s2
fault: Attempt to add read-only file at path file:///private/var/containers/Bundle/Application/9D5150DC-82DD-4220-9898-7438EBA362B3/SomeApp.app/Galaxy.store read/write. Adding it read-only instead. This will be a hard error in the future; you must specify the NSReadOnlyPersistentStoreOption.
CoreData: Attempt to add read-only file at path file:///private/var/containers/Bundle/Application/9D5150DC-82DD-4220-9898-7438EBA362B3/SomeApp.app/Galaxy.store read/write. Adding it read-only instead. This will be a hard error in the future; you must specify the NSReadOnlyPersistentStoreOption.