有谁知道以下 Realm 函数的 try-catch 的语法是什么?
realm.write() {
realm.add(whatever)
}
我收到以下错误:
call can throw but it is not marked with 'try' and the error is not handled
最佳答案
根据我的想象,realm.write() 可以抛出异常。在 Swift 2 中,你使用 do/catch 和 try 来处理异常。
我怀疑你应该做这样的事情:
do {
try realm.write() {
realm.add(whatever)
}
} catch {
print("Something went wrong!")
}
如果realm.write() 抛出异常,print 语句将被立即调用。
关于swift2 - Realm throw catch swift 2.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32651449/