【问题标题】:When let realm = Realm() -> Call can throw, but is not marked with try and the error is not handled [duplicate]当 let realm = Realm() -> 调用可以抛出,但是没有用 try 标记并且错误没有被处理 [重复]
【发布时间】:2015-09-18 00:03:12
【问题描述】:

我刚刚使用 Xcode 7(应用商店版本)将我的项目从 Swift 1.2 迁移到 Swift 2。我正在使用 Realm 进行本地存储并相应地更新了库。

但是每当我在我的代码中这样做时:

let realm = Realm()

我得到一个 Xcode 错误:

Call can throw, but is not marked with try and the error is not handled

任何想法我应该做什么?

【问题讨论】:

    标签: xcode swift realm


    【解决方案1】:

    这个other SO answer 会帮助你。 使用下面的代码:

     let realm = try! Realm()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-01
      • 2015-08-24
      相关资源
      最近更新 更多