SQLITE_TRANSIENT undefined in Swift

后端 未结 1 1103
礼貌的吻别
礼貌的吻别 2020-11-30 09:07

I\'m using xcode 6 and I\'ve imported libsqlite3.dylib and libsqlite3.0.dylib. I\'ve also added the Bridging-Header.h file witch impor

相关标签:
1条回答
  • 2020-11-30 09:14

    The definitions

    #define SQLITE_STATIC      ((sqlite3_destructor_type)0)
    #define SQLITE_TRANSIENT   ((sqlite3_destructor_type)-1)
    

    from <sqlite3.h> are not imported to Swift, probably due to the "unsafe" pointer casting.

    A possible Swift definition is shown in the SQLite.swift project, in Statement.swift:

    let SQLITE_STATIC = sqlite3_destructor_type(COpaquePointer(bitPattern: 0))
    let SQLITE_TRANSIENT = sqlite3_destructor_type(COpaquePointer(bitPattern: -1))
    

    For Swift 2 you will need

    let SQLITE_STATIC = unsafeBitCast(0, sqlite3_destructor_type.self)
    let SQLITE_TRANSIENT = unsafeBitCast(-1, sqlite3_destructor_type.self)
    

    (taken from "Helpers.swift" from the Swift 2 branch of the SQLite.swift project).

    Update for Swift 3:

    let SQLITE_STATIC = unsafeBitCast(0, to: sqlite3_destructor_type.self)
    let SQLITE_TRANSIENT = unsafeBitCast(-1, to: sqlite3_destructor_type.self)
    
    0 讨论(0)
提交回复
热议问题