Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SWIFT

Preload database in app with Realm swift

let defaultPath = Realm.Configuration.defaultConfiguration.fileURL?.path
let path = Bundle.main.path(forResource: "default", ofType: "realm")
if !FileManager.default.fileExists(atPath: defaultPath!), let bundledPath = path {
    do {
        try FileManager.default.copyItem(atPath: bundledPath, toPath: defaultPath!)
    } catch {
        print("Error copying pre-populated Realm (error)")
    }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Preload #database #app #Realm #swift
ADD COMMENT
Topic
Name
8+5 =