I am new to ios development.
I follow this example to use a pre-populated database and change the code a bit
here is the last code i use on AppDelegate -> func application
let defaultPath = Realm.Configuration.defaultConfiguration.path! let path = NSBundle.mainBundle().pathForResource("default", ofType: "realm") if let bundledPath = path { print("use pre-populated database") do { try NSFileManager.defaultManager().removeItemAtPath(defaultPath) try NSFileManager.defaultManager().copyItemAtPath(bundledPath, toPath: defaultPath) } catch { print("remove") print(error) } }
I am testing this on a real device.
It works, but according to the logic of the code, it will always be reset for a pre-populated database. This is checked: after restarting the application, the data is reset.
I tried moveItemAtPath instead of copyItemAtPath . permission error
I tried to delete a file with a populated database after copying. permission error
I tried using a pre-populated database file as the default configuration path in the real world. an error also occurs.
swift realm
Jesse
source share