Sulla base di @segiddins commento, ho deciso di andare con lo spostamento del vecchio database al gruppo di applicazione utilizzando NSFileManager:
let fileManager = NSFileManager.defaultManager()
//Cache original realm path (documents directory)
let originalDefaultRealmPath = RLMRealm.defaultRealmPath()
//Generate new realm path based on app group
let appGroupURL: NSURL = fileManager.containerURLForSecurityApplicationGroupIdentifier("group.AppGroup")!
let realmPath = appGroupURL.path!.stringByAppendingPathComponent("default.realm")
//Moves the realm to the new location if it hasn't been done previously
if (fileManager.fileExistsAtPath(originalDefaultRealmPath) && !fileManager.fileExistsAtPath(realmPath)) {
var error: NSError?
fileManager.moveItemAtPath(originalDefaultRealmPath, toPath: realmPath, error: &error)
if (error != nil) {
println(error)
}
}
//Set the realm path to the new directory
RLMRealm.setDefaultRealmPath(realmPath)
C'è qualche ragione per cui non è possibile spostare il file utilizzando NSFileManager? – segiddins
Apple suggerisce di evitare le API di coordinamento file, in quanto i dati possono essere danneggiati: https://developer.apple.com/library/ios/technotes/tn2408/_index.html – Whoa
Poiché solo la tua app sarà in grado di spostarlo, e tu puoi fallo atomicamente, starai bene – segiddins