lundi 10 août 2015

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

Okay, after some trial and error, I managed to eliminate some of my other errors, although I still have an issue with one command returning the above error. The line is:

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

As far as I can tell, this follows the format of the insert command, except the example on Github uses hard coded values, rather than variables, although I need the variables since the user inputs them.

Just to give a little bit more background: PCharacter is a struct in AppDelegate, while this is a command contained in an Action linked to a button in the ViewController.

Here's the PCharacter struct:

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)
        }
    }
}

Thanks for any help!

Aucun commentaire:

Enregistrer un commentaire