Skip to content

Commit

Permalink
完善 LKDB嵌套引用 的断言提示
Browse files Browse the repository at this point in the history
  • Loading branch information
lijianghuai committed May 7, 2022
1 parent 1e6c959 commit d7d4758
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions LKDBHelper.podspec.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "LKDBHelper",
"version": "2.5.9",
"version": "2.6.0",
"summary": "全自动的插入,查询,更新,删除, an automatic database operation thread-safe and not afraid of recursive deadlock",
"description": "全面支持 NSArray,NSDictionary, ModelClass, NSNumber, NSString, NSDate, NSData, UIColor, UIImage, CGRect, CGPoint, CGSize, NSRange, int,char,float, double, long.. 等属性的自动化操作(插入和查询)",
"homepage": "https://github.com/li6185377/LKDBHelper-SQLite-ORM",
Expand All @@ -10,7 +10,7 @@
},
"source": {
"git": "https://github.com/li6185377/LKDBHelper-SQLite-ORM.git",
"tag": "2.5.9"
"tag": "2.6.0"
},
"platforms": {
"ios": "5.0",
Expand Down
29 changes: 15 additions & 14 deletions LKDBHelper/Helper/NSObject+LKModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ + (NSDateFormatter *)getModelDateFormatter {

///get
- (id)modelGetValue:(LKDBProperty *)property {
id value = [self valueForKey:property.propertyName];
NSString * const pKey = property.propertyName;
id const value = [self valueForKey:pKey];
id returnValue = value;
if (value == nil) {
return nil;
Expand Down Expand Up @@ -173,11 +174,11 @@ - (id)modelGetValue:(LKDBProperty *)property {
returnValue = [value absoluteString];
} else {
if ([value isKindOfClass:[NSArray class]]) {
returnValue = [self db_jsonObjectFromArray:value];
returnValue = [self db_jsonObjectFromArray:value pKey:pKey];
} else if ([value isKindOfClass:[NSDictionary class]]) {
returnValue = [self db_jsonObjectFromDictionary:value];
returnValue = [self db_jsonObjectFromDictionary:value pKey:pKey];
} else {
returnValue = [self db_jsonObjectFromModel:value];
returnValue = [self db_jsonObjectFromModel:value pKey:pKey];
}
returnValue = [self db_jsonStringFromObject:returnValue];
}
Expand Down Expand Up @@ -331,14 +332,14 @@ - (void)modelSetValue:(LKDBProperty *)property value:(NSString *)value {
[self setValue:modelValue forKey:property.propertyName];
}
#pragma mark - 对 model NSArray NSDictionary 进行支持
- (id)db_jsonObjectFromDictionary:(NSDictionary *)dic {
- (id)db_jsonObjectFromDictionary:(NSDictionary *)dic pKey:(NSString *)pKey {
if ([NSJSONSerialization isValidJSONObject:dic]) {
NSDictionary *bomb = @{LKDB_TypeKey: LKDB_TypeKey_JSON, LKDB_ValueKey: dic};
return bomb;
} else {
NSMutableDictionary *toDic = [NSMutableDictionary dictionary];
[dic enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL *_Nonnull stop) {
id jsonObject = [self db_jsonObjectWithObject:obj];
id jsonObject = [self db_jsonObjectWithObject:obj pKey:pKey];
if (jsonObject) {
toDic[key] = jsonObject;
}
Expand All @@ -350,7 +351,7 @@ - (id)db_jsonObjectFromDictionary:(NSDictionary *)dic {
}
return nil;
}
- (id)db_jsonObjectFromArray:(NSArray *)array {
- (id)db_jsonObjectFromArray:(NSArray *)array pKey:(NSString *)pKey {
if ([NSJSONSerialization isValidJSONObject:array]) {
NSDictionary *bomb = @{LKDB_TypeKey: LKDB_TypeKey_JSON, LKDB_ValueKey: array};
return bomb;
Expand All @@ -359,7 +360,7 @@ - (id)db_jsonObjectFromArray:(NSArray *)array {
NSInteger count = array.count;
for (NSInteger i = 0; i < count; i++) {
id obj = [array objectAtIndex:i];
id jsonObject = [self db_jsonObjectWithObject:obj];
id jsonObject = [self db_jsonObjectWithObject:obj pKey:pKey];
if (jsonObject) {
[toArray addObject:jsonObject];
}
Expand All @@ -373,7 +374,7 @@ - (id)db_jsonObjectFromArray:(NSArray *)array {
return nil;
}
///目前只支持 model、NSString、NSNumber 简单类型
- (id)db_jsonObjectWithObject:(id)obj {
- (id)db_jsonObjectWithObject:(id)obj pKey:(NSString *)pKey {
id jsonObject = nil;
if ([obj isKindOfClass:[NSString class]] || [obj isKindOfClass:[NSNumber class]]) {
jsonObject = obj;
Expand All @@ -390,11 +391,11 @@ - (id)db_jsonObjectWithObject:(id)obj {
jsonObject = @{LKDB_TypeKey: LKDB_TypeKey_Date, LKDB_ValueKey: dateString};
}
} else if ([obj isKindOfClass:[NSArray class]]) {
jsonObject = [self db_jsonObjectFromArray:obj];
jsonObject = [self db_jsonObjectFromArray:obj pKey:pKey];
} else if ([obj isKindOfClass:[NSDictionary class]]) {
jsonObject = [self db_jsonObjectFromDictionary:obj];
jsonObject = [self db_jsonObjectFromDictionary:obj pKey:pKey];
} else {
jsonObject = [self db_jsonObjectFromModel:obj];
jsonObject = [self db_jsonObjectFromModel:obj pKey:pKey];
}

if (jsonObject == nil) {
Expand All @@ -403,7 +404,7 @@ - (id)db_jsonObjectWithObject:(id)obj {
return jsonObject;
}

- (id)db_jsonObjectFromModel:(NSObject *)model {
- (id)db_jsonObjectFromModel:(NSObject *)model pKey:(NSString *)pKey {
Class clazz = model.class;
NSDictionary *jsonObject = nil;
if (model.rowid > 0) {
Expand All @@ -416,7 +417,7 @@ - (id)db_jsonObjectFromModel:(NSObject *)model {
jsonObject = [self db_readInfoWithModel:model class:clazz];
}
} else {
NSAssert(NO, @"目前LKDB 还不支持 循环引用。 比如 A 持有 B, B 持有 A,这种的存储");
NSAssert(NO, @"目前LKDB不支持循环引用。Model:%@ Key:%@ Value:%@", self, pKey, model);
}
}
return jsonObject;
Expand Down

0 comments on commit d7d4758

Please sign in to comment.