iOS FMDB

作者: Ello_Orld | 来源:发表于2019-10-24 21:24 被阅读0次

一、配置pod

  1. 创建工程
  2. 在工程目录下, 执行
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
  1. 执行
pod install
  1. 执行完毕后,打开工程目录中的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

相关文章

网友评论

      本文标题:iOS FMDB

      本文链接:https://www.haomeiwen.com/subject/kytjvctx.html