|
| 1 | +// |
| 2 | +// CCSQLiteData.m |
| 3 | +// CCSQLiteDemo |
| 4 | +// |
| 5 | +// Created by dengyouhua on 22/01/2018. |
| 6 | +// Copyright © 2018 CC | ccworld1000@gmail.com. All rights reserved. |
| 7 | +// https://github.com/ccworld1000/CCSQLite |
| 8 | +// |
| 9 | + |
| 10 | +#import "CCSQLiteData.h" |
| 11 | +#import <CCSQLite.h> // if error try #import "CCSQLite/CCSQLite.h" or #import "CCSQLite.h" |
| 12 | + |
| 13 | +#define CCSQLiteDataDB @"CCSQLiteData.sqlite" |
| 14 | + |
| 15 | +@implementation CCSQLiteData |
| 16 | + |
| 17 | ++ (void) writeDataList { |
| 18 | + NSLog(@"writeDataList"); |
| 19 | + |
| 20 | + NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:CCSQLiteDataDB]; |
| 21 | + |
| 22 | + CCKeyValue *kv = [CCKeyValue defaultKeyValueWithPath:path]; |
| 23 | + kv.valueType = CCKeyValueTypeJson; |
| 24 | + |
| 25 | + NSData * data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"list" ofType:@"json"]]; |
| 26 | + [kv setObject:data key:CCKeyValueDataKey]; |
| 27 | +} |
| 28 | + |
| 29 | ++ (NSArray *) readDataListAtPath : (NSString *) path { |
| 30 | + NSArray *list = nil; |
| 31 | + |
| 32 | + if (!path) { |
| 33 | + return list; |
| 34 | + } |
| 35 | + |
| 36 | + CCKeyValue *kv = [CCKeyValue defaultKeyValueWithPath:path]; |
| 37 | + kv.valueType = CCKeyValueTypeJson; |
| 38 | + |
| 39 | + id CCJSON = [kv objectForKey:CCKeyValueDataKey]; |
| 40 | + |
| 41 | + if ([CCJSON isKindOfClass:[NSArray class]]) { |
| 42 | + list = CCJSON; |
| 43 | + } |
| 44 | + |
| 45 | + return list; |
| 46 | +} |
| 47 | + |
| 48 | ++ (NSArray *) readDataList { |
| 49 | + NSLog(@"readDataList"); |
| 50 | + |
| 51 | + NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:CCSQLiteDataDB]; |
| 52 | + return [self readDataListAtPath:path]; |
| 53 | +} |
| 54 | + |
| 55 | ++ (NSArray *) readDefaultDataList { |
| 56 | + NSLog(@"readDefaultDataList"); |
| 57 | + NSString *path = [[NSBundle mainBundle] pathForResource:@"CCSQLiteData" ofType:@"sqlite"]; |
| 58 | + return [self readDataListAtPath:path]; |
| 59 | +} |
| 60 | + |
| 61 | +@end |
0 commit comments