Moving function pointer code to Swift 2

My sqlite code doesn't compile anymore in Swift 2. The problem lines are this:


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


Command clicking to Swift's import of sqlite shows this:


typealias sqlite3_destructor_type = (UnsafeMutablePointer<Void>) -> Void


Coming from the following in sqlite3.h:


typedef void (*sqlite3_destructor_type)(void*);
#define SQLITE_STATIC      ((sqlite3_destructor_type)0)
#define SQLITE_TRANSIENT   ((sqlite3_destructor_type)-1)


Anyone know how to create those two constants in Swift 2.0? Even better if there's some way to import sqlite in Swift 2 without this bridging header stuff.


Rob

I'm also looking for an answer to this.

The type should be displayed as:

typealias sqlite3_destructor_type = @convention(c) (UnsafeMutablePointer<Void>) -> Void

(Even in the latest Xcode 7 beta, `@convention(c)` is not displayed in QuickHelp.)


Maybe you need to use unsafeBitCast.

let SQLITE_STATIC = unsafeBitCast(0, sqlite3_destructor_type.self)
let SQLITE_TRANSIENT = unsafeBitCast(-1, sqlite3_destructor_type.self)
Moving function pointer code to Swift 2
 
 
Q