【问题标题】:CVaListPointer when using objectsWhere() querying Realm database使用 objectsWhere() 查询 Realm 数据库时的 CVaListPointer
【发布时间】:2016-09-18 20:16:58
【问题描述】:

我正在将我的代码更新为 swift 3.0。我使用 Realm 作为数据库。我有以下代码行:

let thisJob = Jobs.objectsWhere("identifier == '\(identify)'")

编译器会抛出一个错误,因为需要一个额外的参数。 “调用中的参数 'args' 缺少参数” 参数是 CVaListPointer。我不确定我应该如何使用这个论点。我试过了:

let thisJob = Jobs.objectsWhere("identifier == '\(identify)'", args: CVaListPointer)

但是,该行的编译器错误是“无法将 CVaListPointer.Type 类型的值转换为预期的参数 CVaListPointer。”

【问题讨论】:

    标签: ios database swift realm nspredicate


    【解决方案1】:

    Objective-C 接口中的可变参数不会在 Swift 中导入,这就是 Realm 为 Realm Objective-C 提供 Swift 包装器的原因:RLMSupport.swift。将其添加到项目的源文件 as described in Realm's installation instructions 中,您就可以使用 Jobs.objectsWhere("identifier == '\(identify)'")

    虽然identify 可以包含在进行字符串插值时应该转义的字符,但最好将其作为格式参数传递:

    Jobs.objectsWhere("identifier == %@", identify)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-02
      相关资源
      最近更新 更多