领域运行时错误
Realm Runtime Error
我最近升级到 Swift 2.0,现在我一直遇到领域问题。最近,我遇到了一个问题,应用程序在第一次出现 "try! Realm()" 时立即崩溃,导致此错误:
fatal error: 'try!' expression unexpectedly raised an error: Error
Domain=io.realm Code=2 "open() failed: No such file or directory"
UserInfo={NSFilePath=/Users/XXXXX/Library/Developer/CoreSimulator/Devices/7299DF18-E7D5-4499-93DD-A5035FB48E67/data/Containers/Data/Application/BED64819-5895-407F-9E90-9888741E24EB/Documents/default.realm,
NSLocalizedDescription=open() failed: No such file or directory, Error
Code=2}: file
/Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-700.0.59/src/swift/stdlib/public/core/ErrorType.swift,
line 50 (lldb)
我看到另一个 post 与此有点相关,但它没有帮助,因为我没有尝试直接调用路径,它只是抛出这个错误。
谢谢
当您在 Swift 中使用 try!
时,您选择忽略错误,否则您可以从中恢复。
在这种情况下,Realm
初始化程序被标记为 throws
。这是 Error Handling 上 Realm 文档的摘录:
Like any disk IO operation, creating a Realm instance could sometimes fail if resources are constrained. In practice, this can only happen the first time a Realm instance is created on a given thread. Subsequent accesses to a Realm from the same thread will reuse a cached instance and will always succeed.
To handle errors when first accessing a Realm on a given thread, use Swift’s built-in error handling mechanism:
do {
let realm = try Realm()
} catch let error as NSError {
// handle error
}
当我通过 Realm 浏览器从 Realm 手动删除一个对象时,同样的事情发生在我身上。
这是我的两分钱:删除 realm.lock 和其他日志文件并重新启动对我有用的应用程序。看看截图:
我最近升级到 Swift 2.0,现在我一直遇到领域问题。最近,我遇到了一个问题,应用程序在第一次出现 "try! Realm()" 时立即崩溃,导致此错误:
fatal error: 'try!' expression unexpectedly raised an error: Error Domain=io.realm Code=2 "open() failed: No such file or directory" UserInfo={NSFilePath=/Users/XXXXX/Library/Developer/CoreSimulator/Devices/7299DF18-E7D5-4499-93DD-A5035FB48E67/data/Containers/Data/Application/BED64819-5895-407F-9E90-9888741E24EB/Documents/default.realm, NSLocalizedDescription=open() failed: No such file or directory, Error Code=2}: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-700.0.59/src/swift/stdlib/public/core/ErrorType.swift, line 50 (lldb)
我看到另一个 post 与此有点相关,但它没有帮助,因为我没有尝试直接调用路径,它只是抛出这个错误。
谢谢
当您在 Swift 中使用 try!
时,您选择忽略错误,否则您可以从中恢复。
在这种情况下,Realm
初始化程序被标记为 throws
。这是 Error Handling 上 Realm 文档的摘录:
Like any disk IO operation, creating a Realm instance could sometimes fail if resources are constrained. In practice, this can only happen the first time a Realm instance is created on a given thread. Subsequent accesses to a Realm from the same thread will reuse a cached instance and will always succeed.
To handle errors when first accessing a Realm on a given thread, use Swift’s built-in error handling mechanism:
do {
let realm = try Realm()
} catch let error as NSError {
// handle error
}
当我通过 Realm 浏览器从 Realm 手动删除一个对象时,同样的事情发生在我身上。 这是我的两分钱:删除 realm.lock 和其他日志文件并重新启动对我有用的应用程序。看看截图: