SQLite的Swift基礎封裝:SQLiteDB

jopen 10年前發布 | 36K 次閱讀 SQLiteDB Apple Swift開發

SQLiteDB 是基礎的 SQLite 的 Swift 封裝。SQLiteDB 非常簡單,不提供任何高級的函數,不完全是 Swift 編寫的,所以跟 Swift 調用 sqlite C API 的方法會有點不同。

  • Create your SQLite database however you like, but name it data.db and then add the data.db file to your Xcode project. (If you want to name the database file something other than data.db, then change the DB_NAME constant in the SQLiteDB 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 included Bridging-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
    }

項目主頁:http://www.baiduhome.net/lib/view/home/1405587328765

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!