SQLite的Swift基础封装:SQLiteDB
jopen
10年前
SQLiteDB 是基础的 SQLite 的 Swift 封装。SQLiteDB 非常简单,不提供任何高级的函数,不完全是 Swift 编写的,所以跟 Swift 调用 sqlite C API 的方法会有点不同。
- Create your SQLite database however you like, but name it
data.db
and then add thedata.db
file to your Xcode project. (If you want to name the database file something other thandata.db
, then change theDB_NAME
constant in theSQLiteDB
class accordingly.) - Add all of the included source files (except for README.md, of course) to your project.
- If you don't have a bridging header file, use the included
Bridging-Header.h
file. If you already have a bridging header file, then copy the contents from the includedBridging-Header.h
file in to your own bridging header file. - If you didn't have a bridging header file, make sure that you modify your project settings to point to the new bridging header file. This will be under the "Build Settings" for your target and will be named "Objective-C Bridging Header".
- Add the SQLite library (libsqlite3.0.dylib) to your project under the "Build Phases" - "Link Binary With Libraries" section.
let data = db.query("SELECT * FROM customers WHERE name='John'") let row = data[0] if let name = row["name"] { textLabel.text = name.string }