Skip to content

Commit 199a234

Browse files
author
ljh
committed
支持 Array,Dictionary,String 可变类型的存储,解决iOS10 NSMutableArray 读取失败的问题
1 parent 1087b41 commit 199a234

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

LKDBHelper.podspec.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "LKDBHelper",
3-
"version": "2.3.3",
3+
"version": "2.3.5",
44
"summary": "全自动的插入,查询,更新,删除, an automatic database operation thread-safe and not afraid of recursive deadlock",
55
"description": "全面支持 NSArray,NSDictionary, ModelClass, NSNumber, NSString, NSDate, NSData, UIColor, UIImage, CGRect, CGPoint, CGSize, NSRange, int,char,float, double, long.. 等属性的自动化操作(插入和查询)",
66
"homepage": "https://github.com/li6185377/LKDBHelper-SQLite-ORM",
@@ -10,7 +10,7 @@
1010
},
1111
"source": {
1212
"git": "https://github.com/li6185377/LKDBHelper-SQLite-ORM.git",
13-
"tag": "2.3.3"
13+
"tag": "2.3.5"
1414
},
1515
"platforms": {
1616
"ios": "4.3",

LKDBHelper/Helper/NSObject+LKModel.m

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ - (id)modelGetValue:(LKDBProperty *)property
124124
return nil;
125125
}
126126
else if ([value isKindOfClass:[NSString class]]) {
127-
returnValue = value;
127+
returnValue = [value copy];
128128
}
129129
else if ([value isKindOfClass:[NSNumber class]]) {
130130
returnValue = [[LKDBUtils numberFormatter] stringFromNumber:value];
@@ -327,7 +327,7 @@ - (void)modelSetValue:(LKDBProperty *)property value:(NSString *)value
327327
}
328328
else if ([columnClass isSubclassOfClass:[NSString class]]) {
329329
if (![LKDBHelper nullIsEmpty] || value.length > 0) {
330-
modelValue = [value copy];
330+
modelValue = [columnClass stringWithString:value];
331331
}
332332
}
333333
else if ([columnClass isSubclassOfClass:[NSNumber class]]) {
@@ -374,7 +374,20 @@ - (void)modelSetValue:(LKDBProperty *)property value:(NSString *)value
374374
}
375375
else {
376376
modelValue = [self db_modelWithJsonValue:value];
377-
if (![modelValue isKindOfClass:columnClass]) {
377+
BOOL isValid = NO;
378+
if ([modelValue isKindOfClass:[NSArray class]] && [columnClass isSubclassOfClass:[NSArray class]]) {
379+
isValid = YES;
380+
modelValue = [columnClass arrayWithArray:modelValue];
381+
}
382+
else if ([modelValue isKindOfClass:[NSDictionary class]] && [columnClass isSubclassOfClass:[NSDictionary class]]) {
383+
isValid = YES;
384+
modelValue = [columnClass dictionaryWithDictionary:modelValue];
385+
}
386+
else if ([modelValue isKindOfClass:columnClass]) {
387+
isValid = YES;
388+
}
389+
///如果类型不对 则设置为空
390+
if (!isValid) {
378391
modelValue = nil;
379392
}
380393
}
@@ -981,4 +994,4 @@ - (void)mutableString:(NSMutableString*)sb appendPropertyStringWithClass:(Class)
981994
}
982995
}
983996

984-
@end
997+
@end

0 commit comments

Comments
 (0)