0

嗨,我是 swift 新手,正在尝试为我的关卡编码项目添加数据库。我似乎无法让不透明的指针在没有错误的情况下正常工作。我使用过教程并且总是遇到同样的错误。我得到的错误:

Expected member name or constructor call after type name on line 3
Cannot convert value of type 'UnsafeMutablePointer<OpaquePointer?.Type>' to expected argument type 'UnsafeMutablePointer<OpaquePointer?>' On line 9
Cannot convert return expression of type 'OpaquePointer?.Type' to return type 'OpaquePointer?' On line 12
    var dbURL = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as String
    
    func createDatabase() -> OpaquePointer?{
        var db = OpaquePointer?
        let url = NSURL(fileURLWithPath: dbURL)
        
        if let pathComponent = url.appendingPathComponent("Database.sqlite"){
            let filePath = pathComponent.path
            if sqlite3_open(filePath, &db) == SQLITE_OK{
                print("successfully opened database")
                
                return db
            }
          
        }
        
    }
4

2 回答 2

0

更改var db = OpaquePointer?var db : OpaquePointer?

添加return nil到函数的末尾。

于 2022-02-03T18:02:34.090 回答
0

您需要在第 3 行使用冒号而不是等号。

于 2022-02-03T18:07:07.257 回答