gpt4 book ai didi

ios - 在 sqlite.swift 中创建多列索引

转载 作者:行者123 更新时间:2023-11-28 08:01:20 25 4
gpt4 key购买 nike

我将 sqlite.swift 更新到版本 0.11.4,当我创建包含两列的索引时,我的编译器报告了一个错误。

在我使用命令之前

try db.run(table.createIndex([column1, column2], unique: true, ifNotExists: true))

更新后,它不再工作了。我应该使用可表达的。但我没那么先进。

Contextual type 'Expressible' cannot be used with array literal

你能帮我一下吗?

谢谢!!!

最佳答案

好的,我想通了这个问题。我在这里添加它以防其他人遇到问题。在以前的 Swift 版本中,您可以将数组传递给可变参数。使用较新版本的 Swift,您不能再这样做了。我不得不更改我的代码:

do {
try db.run(table.createIndex([identifier], ifNotExists: true))
} catch let error {
Log.e("DB: Unable to create index for identifier. Error: \(error.localizedDescription)")
}

到:

do {
try db.run(table.createIndex(identifier, ifNotExists: true))
} catch let error {
Log.e("DB: Unable to create index for identifier. Error: \(error.localizedDescription)")
}

如果需要传递多个参数,用逗号分隔即可。

try db.run(table.createIndex(identifier1, identifier2, identifier3, ifNotExists: true))

关于ios - 在 sqlite.swift 中创建多列索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46609263/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com