境界realmWithPath方法崩潰當我打電話:在iOS
[RLMRealm realmWithPath:@"example.realm"]
它崩潰和原木:
終止應用程序由於未捕獲的異常 'RLMException',原因:「open()的失敗:不允許操作'
除了使用default.realm和[RLMRealm defaultRealm]外,如何創建特定的領域文件?我從文檔中遺漏了什麼嗎?
境界realmWithPath方法崩潰當我打電話:在iOS
[RLMRealm realmWithPath:@"example.realm"]
它崩潰和原木:
終止應用程序由於未捕獲的異常 'RLMException',原因:「open()的失敗:不允許操作'
除了使用default.realm和[RLMRealm defaultRealm]外,如何創建特定的領域文件?我從文檔中遺漏了什麼嗎?
你是正確的,這是創建一個新的境界文件的方式,如果你提供一個完整路徑文件系統的可寫位置,它會工作:
NSString *documentsDirectory = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
NSString *customRealmPath = [documentsDirectory stringByAppendingPathComponent:@"example.realm"];
RLMRealm *realm = [RLMRealm realmWithPath:customRealmPath];
編輯:已更新至上設備工作的路徑以及模擬器
見我的回答https://github.com/realm/realm-cocoa/issues/4221
如果使用捆綁的境界文件,它會在設備崩潰。只需指定只讀
readOnly:領域是否爲只讀(對於只讀 文件,必須爲true)。
let path = Bundle.main.url(forResource: "mydata", withExtension: "realm")!
let configuration = Realm.Configuration(fileURL: path, readOnly: true)
realm = try! Realm(configuration: configuration)
喜蒂姆從這裏來的境界。對於那個很抱歉!我不認爲我們已經看到這個錯誤報告。我需要更多的細節:你是在設備上還是在模擬器中崩潰?你還有磁盤空間嗎? – timanglade 2014-09-25 23:25:14
你好,蒂姆,謝謝你的幫助!我正在使用我的設備iPhone 6測試此功能。我有可用的磁盤空間。我嘗試在示例應用中調用[RLMRealm realmWithPath:@「example.realm」],但它會使應用崩潰。我認爲錯誤意味着我必須先創建example.realm文件才能寫入,但我認爲realmWithPath會自動爲您做。 – kevnguy 2014-09-25 23:59:18
我使用0.85.0並獲得通過的CocoaPods – kevnguy 2014-09-26 00:10:49