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