针对SQLite3为Cocoa 和 Cocoa Touch设计的持久化对象
by Elton on 十.26, 2009, under Database, Mac
向大家推荐一款很不错的轻量级的Cocoa持久化对象 — sqlitepersistentobjects
使用起来跟ActiveRecord很类似,也非常简单
将下载的zip中的所有文件加入你的项目中,然后链接libsqlite3.dylib,之后你就可以声明实体类了。
1 2 3 4 5 6 7 8 9 10 | #import <foundation/foundation.h> #import "SQLitePersistentObject.h" @interface PersistablePerson : SQLitePersistentObject { NSString *lastName; NSString *firstName; } @property (nonatomic, retain) NSString * lastName; @property (nonatomic, retain) NSString * firstName; @end |
然后你可以这样使用它:
1 2 3 | PersistablePerson *person = [[PersistablePerson alloc] init]; person.firstName = @"Joe"; person.lastName = @"Smith"; |
当你打算保存的时候:
1 | [person save]; |
是不是很简单


