#import <Foundation/Foundation.h>
#import "HXStockModel.h"
@interface DataBaseSimple : NSObject
+(id)sharedInstance;
- (BOOL)insertIntoDB:(HXStockModel *)model;
- (BOOL)deleteFromDBWithKey:(int)key;
- (BOOL)updateFromDBWithKey:(int)key andModel:(HXStockModel *)model;
- (HXStockModel *)selectFromDBWithKey:(int)key;
- (NSArray *)selectFromDB;
- (BOOL)cleanDB;
@end
.m文件
#import "DataBaseSimple.h"
#import "FMDatabaseQueue.h"
#import "FMDatabase.h"
@implementation DataBaseSimple
{
FMDatabaseQueue * _dataBaseQueue;
}
+(id)sharedInstance
{
static id _s;
//多线程对self加锁,oc关键词 单例写法
@synchronized(self){
if (_s==nil) {
_s = [[[self class]alloc]init];
}
}
return _s;
}
- (instancetype)init
{
self = [super init];
if (self) {
// 创建 打开