Skip to content

Commit bdae086

Browse files
committed
完美解决属性类型不确定造成的bug.
完美解决属性类型不确定造成的bug.
1 parent 776dff9 commit bdae086

File tree

7 files changed

+14
-51
lines changed

7 files changed

+14
-51
lines changed

BGFMDB.xcodeproj/xcuserdata/biao.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
ignoreCount = "0"
2121
continueAfterRunningActions = "No"
2222
filePath = "BGFMDB/ViewController.m"
23-
timestampString = "542713492.037143"
23+
timestampString = "543403640.977806"
2424
startingColumnNumber = "9223372036854775807"
2525
endingColumnNumber = "9223372036854775807"
26-
startingLineNumber = "411"
27-
endingLineNumber = "411"
26+
startingLineNumber = "414"
27+
endingLineNumber = "414"
2828
landmarkName = "-testT"
2929
landmarkType = "7">
3030
</BreakpointContent>
@@ -84,7 +84,7 @@
8484
ignoreCount = "0"
8585
continueAfterRunningActions = "No"
8686
filePath = "BGFMDB/ViewController.m"
87-
timestampString = "542713492.037796"
87+
timestampString = "543403640.978277"
8888
startingColumnNumber = "9223372036854775807"
8989
endingColumnNumber = "9223372036854775807"
9090
startingLineNumber = "195"
@@ -100,7 +100,7 @@
100100
ignoreCount = "0"
101101
continueAfterRunningActions = "No"
102102
filePath = "BGFMDB/ViewController.m"
103-
timestampString = "542713492.03819"
103+
timestampString = "543403640.978541"
104104
startingColumnNumber = "9223372036854775807"
105105
endingColumnNumber = "9223372036854775807"
106106
startingLineNumber = "190"

BGFMDB/ViewController.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,12 @@ -(void)testT{
401401
testT* test = [testT new];
402402
T2* t2 = [T2 new];
403403
t2.t2 = @"t2";
404+
t2.name = @"t2_name";
404405
/*------*/
405406
T3* t3 = [T3 new];
406407
t3.t3 = @"t3";
408+
t3.name = @"t3_name";
409+
t3.t2 = t2;
407410

408411
test.t1 = t3;
409412
[test bg_save];

BGFMDB/libs/BG/BGModelInfo.m

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ @implementation BGModelInfo
4545
//设置属性值
4646
[info setValue:propertyValue forKey:@"propertyValue"];
4747
sqlValue = [BGTool getSqlValue:propertyValue type:propertyType encode:YES];
48-
//非系统类型特殊处理sqlValue
49-
if(![BGTool isKindOfSystemType:propertyType]){
50-
//设置将要存储到数据库的值
51-
sqlValue = [NSString stringWithFormat:@"%@%@%@",propertyType,BG_CUSTOM_TYPE_SEPARATOR,sqlValue];
52-
}
5348
[info setValue:sqlValue forKey:@"sqlColumnValue"];
5449
[modelInfos addObject:info];
5550
}

BGFMDB/libs/BG/BGTool.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
#define bg_tableNameKey @"bg_tableName"
1616
#define bg_rowid @"rowid"
1717

18-
#define BG_CUSTOM_TYPE_SEPARATOR @":::BGCUSTOMTYPE:::"
19-
2018
#define bg_uniqueKeysSelector NSSelectorFromString(@"bg_uniqueKeys")
2119
#define bg_ignoreKeysSelector NSSelectorFromString(@"bg_ignoreKeys")
2220
#define bg_unionPrimaryKeysSelector NSSelectorFromString(@"bg_unionPrimaryKeys")

BGFMDB/libs/BG/BGTool.m

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030
//100M大小限制.
3131
#define MaxData @(838860800)
3232

33-
//如果有不确定的属性类型时,将此开关打开
34-
//#define HaveDynamicProperty
35-
3633
/**
3734
* 遍历所有类的block(父类)
3835
*/
@@ -219,8 +216,7 @@ +(NSArray*)getClassIvarList:(__unsafe_unretained Class)cla Object:(_Nullable id)
219216
[keys addObject:[NSString stringWithFormat:@"%@*@\"NSString\"",bg_createTimeKey]];
220217
[keys addObject:[NSString stringWithFormat:@"%@*@\"NSString\"",bg_updateTimeKey]];
221218
}
222-
//判断是否有自定义类型标志,有则不缓存.
223-
__block BOOL isKindOfCustomFlag = NO;
219+
224220
[self bg_enumerateClasses:cla complete:^(__unsafe_unretained Class c, BOOL *stop) {
225221
unsigned int numIvars; //成员变量个数
226222
Ivar *vars = class_copyIvarList(c, &numIvars);
@@ -233,30 +229,14 @@ +(NSArray*)getClassIvarList:(__unsafe_unretained Class)cla Object:(_Nullable id)
233229
if (!onlyKey) {
234230
//获取成员变量的数据类型
235231
NSString* type = [NSString stringWithUTF8String:ivar_getTypeEncoding(thisIvar)];
236-
if(![self isKindOfSystemType:type]){
237-
isKindOfCustomFlag = YES;
238-
if(object&&[object valueForKey:key]){
239-
type = [NSString stringWithFormat:@"@\"%@\"",[[object valueForKey:key] class]];
240-
//NSLog(@"自定义 key = %@ , type = %@",key,type);
241-
}
242-
}else{
243-
//NSLog(@"系统 key = %@ , type = %@",key,type);
244-
}
245232
key = [NSString stringWithFormat:@"%@*%@",key,type];
246233
}
247234
[keys addObject:key];//存储对象的变量名
248235
}
249236
free(vars);//释放资源
250237
}];
251238

252-
#ifdef HaveDynamicProperty
253-
if(!isKindOfCustomFlag) {
254-
//缓存的属性信息
255-
[cache setObject:keys forKey:cacheKey];
256-
}
257-
#else
258239
[cache setObject:keys forKey:cacheKey];
259-
#endif
260240

261241
return keys;
262242
}
@@ -533,12 +513,6 @@ +(NSString*)stringWithDate:(NSDate*)date{
533513
+(id)getSqlValue:(id)value type:(NSString*)type encode:(BOOL)encode{
534514
if(!value || [value isKindOfClass:[NSNull class]])return nil;
535515

536-
if(!encode){//特殊处理被重复解码的问题.
537-
if(![value isKindOfClass:[NSString class]]){
538-
return value;
539-
}
540-
}
541-
542516
if([type containsString:@"String"]){
543517
if([type containsString:@"AttributedString"]){//处理富文本.
544518
if(encode) {
@@ -661,12 +635,9 @@ +(id)getSqlValue:(id)value type:(NSString*)type encode:(BOOL)encode{
661635
return value;
662636
}else{
663637
if(encode){
664-
NSString* jsonString = [self jsonStringWithObject:value];
665-
return jsonString;
638+
return [self jsonStringWithArray:@[value]];
666639
}else{
667-
NSDictionary* dict = [self jsonWithString:value];
668-
type = [type substringWithRange:NSMakeRange(2,type.length-3)];
669-
return [self objectFromJsonStringWithTableName:type class:NSClassFromString(type) valueDict:dict];
640+
return [self arrayFromJsonString:value].firstObject;
670641
}
671642
}
672643
}
@@ -736,11 +707,6 @@ +(id)objectFromJsonStringWithTableName:(NSString* _Nonnull)tablename class:(__un
736707

737708
if ([tempSqlKey isEqualToString:key]){
738709
NSString* tempValue = valueDict[sqlKey];
739-
if([tempValue isKindOfClass:[NSString class]] && [tempValue containsString:BG_CUSTOM_TYPE_SEPARATOR]){
740-
NSArray* arrTempTV = [tempValue componentsSeparatedByString:BG_CUSTOM_TYPE_SEPARATOR];
741-
type = [arrTempTV firstObject];
742-
tempValue = [arrTempTV lastObject];
743-
}
744710
id ivarValue = [self getSqlValue:tempValue type:type encode:NO];
745711
!ivarValue?:[object setValue:ivarValue forKey:key];
746712
[keyAndTypes removeObject:keyAndType];

BGFMDB/people.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@
107107

108108
@class T1;
109109
@interface testT:NSObject
110-
@property(nonatomic,strong)id t1;
110+
@property(nonatomic,strong) id t1;
111111
@end
112112

113113
@interface T1: NSObject
114-
@property(nonatomic,copy)NSString* name;
114+
@property(nonatomic,copy) NSString* name;
115115
@end
116116

117117
@interface T2: T1
@@ -120,4 +120,5 @@
120120

121121
@interface T3 : T1
122122
@property(nonatomic,copy) NSString* t3;
123+
@property(nonatomic,strong) id t2;
123124
@end

0 commit comments

Comments
 (0)