1

由于您将库更新为 Int64,我无法再编译我的代码。我不断遇到这样的更新方法问题:

let id = Expression<String>("id")
let categoryId = Expression<Int64>("categoryId")
let languageId = Expression<String>("languageId")
let name = Expression<String>("name")
let thumb = Expression<Blob?>("thumb")
let modificationDate = Expression<String>("modificationDate")
let isCurrent = Expression<Int64>("isCurrent")
let isLocal = Expression<Int64>("isLocal")
let needsUpdate = Expression<Int64>("needsUpdate")
let progress = Expression<Double>("progress")

let brochureToUpdate = table.filter(id == brochure.pdfId).update(isLocal <- Int64(brochure.isLocal), needsUpdate <- Int64(brochure.needsUpdate)).changes

我已将所有表达式从表达式更改为表达式,并且所有绑定到表达式的 Int 都是 Int64。

我得到:如果我删除更改,则找不到成员“更改”我得到:找不到成员“更新”

4

3 回答 3

1

我看不到是什么brochure,但如果brochure.pdfId返回 a 以外的任何内容,我会得到相同的结果String

当你有一个链式表达式时,可能很难推断出 Swift 错误。解决问题的一种方法是将其分解为多个步骤:

let filter = table.filter(id == brochure.pdfId) // fails
filter.update(
    isLocal <- Int64(brochure.isLocal),
    needsUpdate <- Int64(brochure.needsUpdate)
).changes

这样,你会得到一个更有帮助的错误。例如,如果brochure.pdfId返回Int: Binary operator '==' cannot be applied to operands of type 'Expression<String>' and 'Int'

更改为以下内容应该有望使事情得以编译:

table.filter(id == String(brochure.pdfId))

其他想法...

你有什么理由切换到Int64任何地方吗?您应该仍然可以在Int不需要 64 位精度的任何地方使用。您甚至可以将类型Bool用于布尔值:

let isCurrent = Expression<Bool>("isCurrent")
let isLocal = Expression<Bool>("isLocal")

通过扩展,您甚至可以使用NSDate

let modificationDate = Expression<NSDate>("modificationDate")
于 2015-03-04T17:07:40.450 回答
1

谢谢斯蒂芬,

使用

while statement.step() {
    .....
}

成功了。我可以使用 Bool 并且不会抱怨 Int。

我确实在文档上看到了 while statement.step() ,是未记录的功能吗?

于 2015-03-05T16:47:39.417 回答
0

我试过这个:

    let brochureToUpdate = table.filter(id == "dfdf")
    brochureToUpdate.update(
        isLocal <- Int64(brochure.isLocal),
        needsUpdate <- Int64(brochure.needsUpdate)
    ).changes

我得到“声明”没有名为“更改”的成员

如果我试试这个:

    let brochureToUpdate = table.filter(id == "dfdf")
    brochureToUpdate.update(
        isLocal <- Int64(brochure.isLocal),
        needsUpdate <- Int64(brochure.needsUpdate)
    )

无法使用类型为“($T9,$T17)”的参数列表调用“更新”

小册子.isLocal 和小册子.needsUpdate 都是 Int64

正如我在评论中所说,如果我不使用 Int64 但 Int 我不会收到任何编译错误,但在运行时它会在这里崩溃:

  for row in statement{
      var isLocal = row[6] as Int
  }
于 2015-03-05T10:47:05.580 回答