无法使用类型的参数列表调用 'insert'

Cannot invoke 'insert' with an argument list of type

将记录插入 table 的代码在最新更新之前工作正常,但现在抛出了这个错误,所以我想知道我做错了什么。

记录插入的示例代码:

   Recipes.insert(Title <- "Chocolate Cake", Description <- "Rich and moist", CookTime <- 20, PictureURL <- "http://w2.fnstatic.co.uk/sites/default/files/pictures/articles/omg-chocolate-cake-7.jpg", VideoURL <- "https://www.youtube.com/watch?v=ZqMqTB7RSjo", Instructions <- "Prepare ingredients into bowl. Whisk for 20 mins, and pour into cake moulding tin. Place in oven at 200C for 15 minutes. Allow 10 mins to cool before icing with chocolate frosting.", Category <- "Desert", Ingredients <- "50g Flour, 200ml Milk, 2 large eggs, Choclate frosting", Favourited <- false)

数据库设置示例:

import Foundation
import SQLite
let path = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first as! String  
let db = Database("\(path)/databasetest.sqlite3")

let Recipes = db["Recipes"]
let RecipeID = Expression<Int>("RecipeID")
let Title = Expression<String>("Title")
let Description = Expression<String>("Description")
let CookTime = Expression<Int>("CookTime")
let PictureURL = Expression<String>("PictureURL")
let VideoURL = Expression<String>("VideoURL")
let Instructions = Expression<String>("Instructions")
let Category = Expression<String>("Category")
let Ingredients = Expression<String>("Ingredients")
let Favourited = Expression<Bool>("Favourited")

func TableSetup() {

db.create(table: Recipes, ifNotExists: true) { t in
    t.column(RecipeID, primaryKey: true)
    t.column(Title)
    t.column(Description)
    t.column(CookTime)
    t.column(PictureURL)
    t.column(VideoURL)
    t.column(Instructions)
    t.column(Category)
    t.column(Ingredients)
    t.column(Favourited, defaultValue: false)
}

我正在使用 stephencelis 的 SQLite.swift 项目。 https://github.com/stephencelis/SQLite.swift

在 SQLite.swift 的早期版本中,insert 函数有重载,在 Swift 1.1 中,可以用尾随 ? 来消除歧义。 Swift 删除了此功能,其迁移器将自动为您删除 ?,从而破坏 SQLite.swift.

包括的解决方案:

  1. 使用!消除歧义(如果语句应该总是成功并且失败时崩溃是可以的):

    Recipes.insert(Title <- "Chocolate Cake", …)!
    
  2. 使用iflet消除歧义(并在块内分组成功逻辑):

    if let rowid = Recipes.insert(Title <- "Chocolate Cake", …) {
        // success logic
    }
    
  3. 调用元组成员,rowidstatement:

    Recipes.insert(Title <- "Chocolate Cake", …).rowid
    

这是一个常见的混淆点,SQLite.swift 最终删除了重载,这意味着现在可以调用 insert 而无需消除歧义:

Recipes.insert(Title <- "Chocolate Cake", …)