一、配置pod
- 创建工程
- 在工程目录下, 执行
pod init
3.打开生成的PodFile文件,添加
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'test1024' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for test1024
pod 'FMDB'
end
- 执行
pod install
- 执行完毕后,打开工程目录中的project..xcworkspace文件。
二、数据库的使用
#import <Foundation/Foundation.h>
#import "FMDatabase.h"
@interface TestDatabaseHandler : NSObject
@property(nonatomic, strong)FMDatabase *db;
+(TestDatabaseHandler *) shareManager;
//初始化数据库
-(FMDatabase *)configDatabase;
@end
#import "TestDatabaseHandler.h"
@implementation TestDatabaseHandler
+(TestDatabaseHandler *)shareManager {
static TestDatabaseHandler *shareManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
if (shareManager == nil) {
shareManager = [[TestDatabaseHandler alloc]init];
}
});
return shareManager;
}
-(FMDatabase *) configDatabase {
NSString *dbPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0] stringByAppendingPathComponent:@"test.db"];
NSLog(@"path = %@", dbPath );
self.db = [FMDatabase databaseWithPath:dbPath];
if (self.db.open) {
return self.db;
}
if ([self.db open]) {
NSLog(@"OPEN DB SUCCESS");
}else{
NSLog(@"OPEN DB FAIL");
}
return self.db;
}
@end
网友评论