ios mysql例項 iOS資料庫的基本使用

2021-10-17 16:09:45 字數 1267 閱讀 4001

今天總結下資料庫的基本使用方法:

ios使用的資料庫一般就是sqlite3,在使用該資料庫前一定要先導入資料庫框架,否則會出錯,接下來引入標頭檔案#import

在工程裡建立乙個model類student,乙個資料庫工具類databasetool

在student.h中定義幾條屬性:

#import

@inte***ce

student : nsobject

@property(nonatomic,copy)nsstring

*name;

@property(nonatomic,copy)nsstring

*hobby;

@property(nonatomic,assign)nsinteger

age;

@end

databasetool.h中對資料庫操作方法的宣告:

#import

#import

#import "student.h"

@inte***ce databasetool : nsobject

//用來儲存資料庫物件的位址

sqlite3 *dbpoint;

//為了保證當前資料庫在工程裡是唯一的,我們用單例的方式建立乙個資料庫工具物件

+ (databasetool *)sharedatabasetool;

//開啟資料庫

- (void)opendb;

//給資料庫建立張**,table

- (void)createtable;

//插入乙個學生資訊

- (void)insertstu:(student *)stu;

//更新乙個學生資訊

- (void)updatestu:(student *)stu;

//刪除操作

- (void)deletedatestu:(student

*)stu;

//查詢操作

- (nsmutablearray *)selectallstu;

//關閉資料庫

- (void)closedb;

@end

databasetool.m中實現方法:

#import "databasetool.h"

@implementation databasetool

+ (databasetool *)sharedatabasetoolelseelseelse elseelseelseelse{

nslog(@"資料庫關閉失敗");

@end

ios mysql例項 iOS資料庫的使用

ios常用的資料訪問方式。1.存檔案。2.存nsuserdefault,這種方式是以plist檔案儲存的,也是持久化的一種。3.資料庫。蘋果自帶的框架是coredata,可以匯入sqlite3使用sqlite資料庫。還可以使用fmdb,它是對sqlite資料庫的封裝,開發者不用面對c語言的sqlit...

IOS例項隨筆

工廠方法例項化 用於簡化物件的例項化 通常與類名相同。首字母小寫 工廠方法可以傳遞引數 id 類名 彈出輸入 endediting yes 在類檔案的.h檔案中之所以對檢視是weak弱引用,是因為在nib檔案中 故事板和xib 是已經強引用了 可以用for in方法快速將檢視放入陣列中 iskind...

iOS 例項變數

不需要 synthesize語句 在某個版本之前,對應 property,在implementation中需要寫對應的 synthesize語句,來合成access方法,不過在一次公升級之後,現在已經不再需要了 不需要重複宣告例項變數 實際上,property宣告的是屬性,並不是例項變數。但是編譯器...