1
我嘗試按照「綁定領域與應用程序」文檔。我嘗試使用方法Realm().writeCopyToPath(_:encryptionKey:))
,但問題是我無法在我的OSX上的特定位置上創建文件。它顯示錯誤,該文件已經退出。請給我用writeCopyToPathwriteCopyToPath Realm不起作用
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
window = UIWindow(frame: UIScreen.mainScreen().bounds)
window?.rootViewController = UIViewController()
window?.makeKeyAndVisible()
NSFileManager.defaultManager().removeItemAtPath(Realm.Configuration.defaultConfiguration.path!, error: nil)
// Create a standalone object
var mydog = Dog()
// Set & read properties
mydog.name = "Rex"
mydog.age = 9
println("Name of dog: \(mydog.name)")
// Realms are used to group data together
let realm = Realm() // Create realm pointing to default file
println(realm.writeCopyToPath("/Users/taforyou/CU-TEP",encryptionKey: nil))
// Save your object
realm.beginWrite()
realm.add(mydog)
realm.commitWrite()
return true
}
}
輸出日誌以正確的方式在運行
Name of dog: Rex
Optional(Error Domain=io.realm Code=4 "open() failed: File exists" UserInfo=0x7fbc704a8cd0 {NSLocalizedDescription=open() failed: File exists, Error Code=4})
謝謝
境界0.95
哦,這可能會奏效,謝謝jpsim –