SQLite.Swift: 无法使用类型为“(Setter, Setter, Setter)”的参数列表调用 'insert'

SQLite.Swift: Cannot invoke 'insert' with an argument list of type '(Setter, Setter, Setter)'

好的,经过反复试验,我设法消除了一些其他错误,尽管我仍然有一个命令返回上述错误的问题。该行是:

PCharacter.PCharacters.insert(PCharacter.charName <- "\(newCharName)", 
    PCharacter.maxHP <- "\(newCharHP)", PCharacter.maxMP <- "\(newCharMP)")

据我所知,这遵循插入命令的格式,除了 Github 上的示例使用硬编码值,而不是变量,尽管我需要这些变量,因为用户输入了它们。

只是为了提供更多背景知识:PCharacter 是 AppDelegate 中的一个结构,而这是包含在链接到 ViewController 中按钮的 Action 中的命令。

这是 PCharacter 结构:

struct PCharacter {
    static let PCharacters = db["PCharacters"]
    static let id = Expression<Int64>("id")
    static let charName = Expression<String>("charName")
    static let currentHP = Expression<Int64>("currentHP")
    static let maxHP = Expression<Int64>("maxHP")
    static let currentMP = Expression<Int64>("currentMP")
    static let maxMP = Expression<Int64>("maxMP")
    static let currentExp = Expression<Int64>("currentExp")
    static let nextExp = Expression<Int64>("nextExp")
    static let charWeaponID = Expression<Int64>("charWeaponID")

    static func createTable() {
        db.create(table: PCharacters) { t in
            t.column(id, primaryKey: .Autoincrement)
            t.column(charName, unique: true)
            t.column(currentHP)
            t.column(maxHP)
            t.column(currentMP)
            t.column(maxMP)
            t.column(currentExp)
            t.column(nextExp)
            t.foreignKey(charWeaponID, references: Weapon.Weapons[id], delete: .SetNull)
        }
    }
}

感谢您的帮助!

有一个 section of the Contributing Guidelines 涵盖了这个确切的错误。如果您将 insert 分成多行,您将在以下两行中梳理出正确的错误消息:

PCharacter.maxHP <- "\(newCharHP)"
PCharacter.maxMP <- "\(newCharMP)"

Binary operator '<-' cannot be applied to operands of type 'Expression' and 'String'

您的 maxHPmaxMP 列是 Int64,但您将它们设置为字符串值。确保 newCharHPnewCharMP 都是 Int64.