与 SQLITE 中的不透明指针作斗争 swift

Struggling with Opaque Pointers in SQLITE swift

您好,我是 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
            }
          
        }
        
    }

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

在函数末尾添加return nil

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