一个好用的sqlite3工具类
发布时间:2020-12-12 20:07:47 所属栏目:百科 来源:网络整理
导读:基于FMDatabase的一层很薄的封装,主要目的是消除反复open close数据库的冗余代码,并以单例的形式暴露 #import "YLSDatabaseHelper.h"#import "YLSGlobalUtils.h"@implementation YLSDatabaseHelper{ FMDatabase* db;}-(id) init{ self = [super init]; if(
|
基于FMDatabase的一层很薄的封装,主要目的是消除反复open close数据库的冗余代码,并以单例的形式暴露 #import "YLSDatabaseHelper.h"
#import "YLSGlobalUtils.h"
@implementation YLSDatabaseHelper
{
FMDatabase* db;
}
-(id) init
{
self = [super init];
if(self){
NSString *dbFilePath = [YLSGlobalUtils getDatabaseFilePath];
db = [[FMDatabase alloc] initWithPath:dbFilePath];
}
return self;
}
+(YLSDatabaseHelper*) sharedInstance
{
static dispatch_once_t pred = 0;
__strong static id _sharedObject = nil;
dispatch_once(&pred,^{
_sharedObject = [[self alloc] init];
});
return _sharedObject;
}
-(void) doOperation:(void(^)(FMDatabase*))block
{
[db open];
block(db);
[db close];
}
@end (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
