我正在使用xcode 6,并且已经导入libsqlite3.dylib和libsqlite3.0.dylib。我还添加了Bridging- Header.h文件巫婆导入sqlite3.h
libsqlite3.dylib
libsqlite3.0.dylib
Bridging- Header.h
我可以打开SQLite数据库并执行简单操作,例如插入选择…
用 if (sqlite3_bind_text(compiledStatement, 2, Name.cStringUsingEncoding(NSUTF8StringEncoding), -1, SQLITE_TRANSIENT) != SQLITE_OK)
if (sqlite3_bind_text(compiledStatement, 2, Name.cStringUsingEncoding(NSUTF8StringEncoding), -1, SQLITE_TRANSIENT) != SQLITE_OK)
我有一个错误: Use of unresolved identifier 'SQLITE_TRANSIENT'
Use of unresolved identifier 'SQLITE_TRANSIENT'
我做什么表演?我是Swift的新手,这是我在Stack上的第一个问题,请有人帮助我!
定义
#define SQLITE_STATIC ((sqlite3_destructor_type)0) #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
from <sqlite3.h>不会导入到Swift中,可能是由于“不安全”的指针强制转换。
<sqlite3.h>
SQLite.swift项目的 Statement.swift中显示了可能的Swift定义 :
let SQLITE_STATIC = sqlite3_destructor_type(COpaquePointer(bitPattern: 0)) let SQLITE_TRANSIENT = sqlite3_destructor_type(COpaquePointer(bitPattern: -1))
对于 Swift 2, 您将需要
let SQLITE_STATIC = unsafeBitCast(0, sqlite3_destructor_type.self) let SQLITE_TRANSIENT = unsafeBitCast(-1, sqlite3_destructor_type.self)
(摘自SQLite.swift项目的Swift 2分支的“ Helpers.swift”)。
Swift 3 更新 :
let SQLITE_STATIC = unsafeBitCast(0, to: sqlite3_destructor_type.self) let SQLITE_TRANSIENT = unsafeBitCast(-1, to: sqlite3_destructor_type.self)