打开时Swift和Sqlite3错误

时间:2014-12-24 18:27:55

标签: swift sqlite ios8

我的问题是这段代码在项目开始时给出参数#1缺少参数的错误:

class ViewController: UIViewController {

    @IBOutlet var lineFields: [UITextField]!

    var database: COpaquePointer = nil
    var result = sqlite3_open(dataFilePath(), &database)


    if result == SQLITE3_OK {

        sqlite3_close(database)
        println("Failed to open connection")
        return
    }

    func dataFilePath() -> String {

        let paths = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)
        let documentDirectory = paths[0] as NSString
        return documentDirectory.stringByAppendingPathComponent("data.sqlite") as String

    }

var结果是错误的地方,有人可以告诉我原因。我已经添加了libsqlite3.dylib并创建了所需的桥,任何帮助??谢谢。 Xcode pic with error

1 个答案:

答案 0 :(得分:1)

正如我在评论中提到的,sqlite3_open采用cString而不是String

您需要将通话更改为:

var result = sqlite3_open((dataFilePath() as NSString).UTF8String, &database)