Skip to content

Commit

Permalink
重新封装抽取了FMDB
Browse files Browse the repository at this point in the history
增加了FMDB可以直接存储对象的功能
  • Loading branch information
huangzhibiao committed Sep 28, 2016
0 parents commit c5b76df
Show file tree
Hide file tree
Showing 56 changed files with 8,078 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
685 changes: 685 additions & 0 deletions BGFMDB.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions BGFMDB.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "1"
version = "2.0">
</Bucket>
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D706630C1CD1EF67009E4B4D"
BuildableName = "BGFMDB.app"
BlueprintName = "BGFMDB"
ReferencedContainer = "container:BGFMDB.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D70663251CD1EF67009E4B4D"
BuildableName = "BGFMDBTests.xctest"
BlueprintName = "BGFMDBTests"
ReferencedContainer = "container:BGFMDB.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D70663301CD1EF67009E4B4D"
BuildableName = "BGFMDBUITests.xctest"
BlueprintName = "BGFMDBUITests"
ReferencedContainer = "container:BGFMDB.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D706630C1CD1EF67009E4B4D"
BuildableName = "BGFMDB.app"
BlueprintName = "BGFMDB"
ReferencedContainer = "container:BGFMDB.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D706630C1CD1EF67009E4B4D"
BuildableName = "BGFMDB.app"
BlueprintName = "BGFMDB"
ReferencedContainer = "container:BGFMDB.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D706630C1CD1EF67009E4B4D"
BuildableName = "BGFMDB.app"
BlueprintName = "BGFMDB"
ReferencedContainer = "container:BGFMDB.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>BGFMDB.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>D706630C1CD1EF67009E4B4D</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>D70663251CD1EF67009E4B4D</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>D70663301CD1EF67009E4B4D</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
Binary file added BGFMDB/.DS_Store
Binary file not shown.
17 changes: 17 additions & 0 deletions BGFMDB/AppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// AppDelegate.h
// BGFMDB
//
// Created by huangzhibiao on 16/4/28.
// Copyright © 2016年 Biao. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;


@end

45 changes: 45 additions & 0 deletions BGFMDB/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// AppDelegate.m
// BGFMDB
//
// Created by huangzhibiao on 16/4/28.
// Copyright © 2016年 Biao. All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
38 changes: 38 additions & 0 deletions BGFMDB/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Binary file added BGFMDB/BGFMDB/.DS_Store
Binary file not shown.
100 changes: 100 additions & 0 deletions BGFMDB/BGFMDB/BGFMDB.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//
// BGFMDB.h
// BGFMDB
//
// Created by huangzhibiao on 16/4/28.
// Copyright © 2016年 Biao. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface BGFMDB : NSObject

/**
获取单例函数
*/
+(instancetype)intance;
/**
数据库中是否存在表
*/
- (void)isExistWithTableName:(NSString*)name complete:(void (^)(BOOL isExist))complete;
/**
默认建立主键id
创建表(如果存在则不创建) keys 数据存放要求@[字段名称1,字段名称2]
*/
-(void)createTableWithTableName:(NSString*)name keys:(NSArray*)keys complete:(void (^)(BOOL isSuccess))complete;
/**
插入 只关心key和value @{key:value,key:value}
*/
-(void)insertIntoTableName:(NSString*)name Dict:(NSDictionary*)dict complete:(void (^)(BOOL isSuccess))complete;
/**
keys存放的是要查询的哪些key,为nil时代表查询全部
根据条件查询字段
返回的数组是字典( @[@{key:value},@{key:value}] )
where形式 @[@"key",@"=",@"value",@"key",@">=",@"value"]
*/
-(void)queryWithTableName:(NSString*)name keys:(NSArray*)keys where:(NSArray*)where complete:(void (^)(NSArray* array))complete;
/**
全部查询 返回的数组是字典( @[@{key:value},@{key:value}] )
*/
-(void)queryWithTableName:(NSString*)name complete:(void (^)(NSArray* array))complete;
/**
根据key更新value
valueDict 存放的是key和value
where数组的形式 @[@"key",@"=",@"value",@"key",@">=",@"value"],为nil时设置全部
*/
-(void)updateWithTableName:(NSString*)name valueDict:(NSDictionary*)valueDict where:(NSArray*)where complete:(void (^)(BOOL isSuccess))complete;
/**
根据表名和条件删除表内容
where形式 @[@"key",@"=",@"value",@"key",@">=",@"value"],where要非空
*/
-(void)deleteWithTableName:(NSString*)name where:(NSArray*)where complete:(void (^)(BOOL isSuccess))complete;
/**
根据表名删除表格全部内容
*/
-(void)clearTable:(NSString*)name complete:(void (^)(BOOL isSuccess))complete;
/**
删除表
*/
-(void)dropTable:(NSString*)name complete:(void (^)(BOOL isSuccess))complete;

/**----------------------------------华丽分割线---------------------------------------------*/
#pragma mark --> 以下是存储一个对象的API

/**
存储一个对象
*/
-(void)saveObject:(id)object complete:(void (^)(BOOL isSuccess))complete;
/**
查询全部对象
*/
-(void)queryAllObject:(__unsafe_unretained Class)cla complete:(void (^)(NSArray* array))complete;
/**
cla代表对应的类
根据条件查询某个对象
keys存放的是要查询的哪些key,为nil时代表查询全部
where形式 @[@"key",@"=",@"value",@"key",@">=",@"value"]
*/
-(void)queryObjectWithClass:(__unsafe_unretained Class)cla keys:(NSArray*)keys where:(NSArray*)where complete:(void (^)(NSArray* array))complete;
/**
cla代表对应的类
根据条件改变对象的值
valueDict 存放的是key和value
where数组的形式 @[@"key",@"=",@"value",@"key",@">=",@"value"],为nil时设置全部
*/
-(void)updateWithClass:(__unsafe_unretained Class)cla valueDict:(NSDictionary*)valueDict where:(NSArray*)where complete:(void (^)(BOOL isSuccess))complete;
/**
cla代表对应的类
根据条件删除对象表中的对象数据
where形式 @[@"key",@"=",@"value",@"key",@">=",@"value"],where要非空
*/
-(void)deleteWithClass:(__unsafe_unretained Class)cla where:(NSArray*)where complete:(void (^)(BOOL isSuccess))complete;
/**
根据类删除此类所有表数据
*/
-(void)clearWithClass:(__unsafe_unretained Class)cla complete:(void (^)(BOOL isSuccess))complete;
/**
根据类,删除这个类的表
*/
-(void)dropWithClass:(__unsafe_unretained Class)cla complete:(void (^)(BOOL isSuccess))complete;
@end
Loading

0 comments on commit c5b76df

Please sign in to comment.