Swift 2.3:使用Thread1打开sqlite:EXC_BAD_INSTRUCTION代码EXC_I386_INVOP子代码0x0

时间:2016-10-23 07:08:57

标签: swift xcode sqlite

我讨厌这个错误

  

Thread1:EXC_BAD_INSTRUCTION代码EXC_I386_INVOP子代码0x0

http://imgur.com/a/wk6zf

我一直不知道这出现了什么。

我有谷歌这个错误,但有很多种情况。

有什么想法吗?

var statement = COpaquePointer()
//var data:NSMutableArray = []
var data: [[String: AnyObject]] = []

func loadData() {

    let db_path = NSBundle.mainBundle().pathForResource("Recipes", ofType: "sqlite")
    var db = COpaquePointer()

    let status = sqlite3_open(db_path!,&db)
    if (status == SQLITE_OK) {
        print("Open the sqlite success!\n")
    }else {
        print("Open the sqlite failed!\n")
    }

    let query_stmt = "SELECT * FROM recipe"
    if(sqlite3_prepare_v2(db , query_stmt, -1, &statement, nil) == SQLITE_OK) {
        //self.data.removeAllObjects()
        while (sqlite3_step(statement) == SQLITE_ROW) {
            var recipeArray: [String: AnyObject] = [:]

            let recipeName = sqlite3_column_text(statement, 0)
            let recipe_name = String.fromCString(UnsafePointer<CChar>(recipeName)) ?? ""

            let recipeType = sqlite3_column_text(statement, 1)
            let recipe_type = String.fromCString(UnsafePointer<CChar>(recipeType)) ?? ""

            let recipeImage = sqlite3_column_text(statement, 2)
            let recipe_image = String.fromCString(UnsafePointer<CChar>(recipeImage)) ?? ""

            let recipeIsFavor = sqlite3_column_int(statement, 3)
            let recipe_isFavor = Int(recipeIsFavor)

            let recipeUserPhoto = sqlite3_column_text(statement, 4)
            let recipe_userPhoto = String.fromCString(UnsafePointer<CChar>(recipeUserPhoto)) ?? ""

            let recipeUserName = sqlite3_column_text(statement, 5)
            let recipe_userName = String.fromCString(UnsafePointer<CChar>(recipeUserName)) ?? ""

            recipeArray["recipeName"] = recipe_name
            recipeArray["recipeType"] = recipe_type
            recipeArray["recipeImage"] = recipe_image
            recipeArray["recipIsFavor"] = recipe_isFavor
            recipeArray["recipeUserPhoto"] = recipe_userPhoto
            recipeArray["recipeUserName"] = recipe_userName

            data.append(recipeArray)
        }

        sqlite3_finalize(statement)
    }else {
        print("read the sqlite data failed")
    }

}

0 个答案:

没有答案