這裡採用乙個二次封裝的例項來初步演示和實現
更新)如果嫌麻煩,這裡放乙個,建議github
你將有這幾個檔案
其中data.db是database檔案
讓後組織進 project
最好放在最外面,使用時就不必新增子目錄
修改 building settings -> swift compiler - general ->objective-c bridging header
寫成剛剛新增的 頭檔名
//1. 連線資料庫
var db:
sqlitedb
!
//2. 開啟鏈結資料庫
db =
sqlitedb
.shared
_= db.
opendb()
//不需要使用返回值
//使用sql語句
let sqlread =
"select * from student"
let data = db.
query
(sql: sqlread)
//返回乙個字典,query 詢問
let sqlinsert =
"insert into student(stuid ,stuname) values('\(id)
' ,'\(name)
')"_
= db.
execute
(sql: sqlinsert)
// sql 執行
import
uikit
struct
stuinfo
class
viewcontroller
:uiviewcontroller
,uitableviewdelegate
,uitableviewdatasource
func
readstudatafromdb()
}@ibaction
func
b***eletaction
(_ sender:
uibutton
)@ibaction
func
btnaddaction
(_ sender:
uibutton
)func
tableview
(_ tableview:
uitableview
, numberofrowsinsection section:
int)
->
intfunc
tableview
(_ tableview:
uitableview
, cellforrowat indexpath:
indexpath)-
>
uitableviewcell
//刪除
SQLite指南 1 SQLite的特性
使用sqlite也有一段時日了,一直想整理出乙份比較完整的sqlite指南,可惜時間總是不夠。就從這裡開始吧,能寫多少就寫多少。總特性 1.用作應用程式的檔案格式,比如儲存xml或者一些特定格式的檔案,這樣可以避免使用專有的解析器。這種檔案至少可以跨平台讀取並且具備事務的特性。用作配置檔案,確實不錯...
iOS 資料持久化四 SQLite3 1
下邊的內容是由這來的 以下介紹幾個常用的指令,分享給大家 1 開啟 關閉資料庫 使用資料庫的第一件事,就是建立乙個資料庫。要注意的是,在ios環境下,只有document directory 是可以進行讀寫的。在寫程式時用的那個resource資料夾底下的東西都是read only。因此,建立的資料...
iOS 資料持久化四 SQLite3 1
下邊的內容是由這來的 以下介紹幾個常用的指令,分享給大家 1 開啟 關閉資料庫 使用資料庫的第一件事,就是建立乙個資料庫。要注意的是,在ios環境下,只有document directory 是可以進行讀寫的。在寫程式時用的那個resource資料夾底下的東西都是read only。因此,建立的資料...