Skip to content

Commit a96c1e3

Browse files
committed
获取只读属性的set方法
1 parent 47bc707 commit a96c1e3

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

LKDBHelper/Helper/NSObject+LKModel.m

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ -(NSString *)db_tableName
8282
}
8383
-(BOOL)db_inserting
8484
{
85-
return [objc_getAssociatedObject(self, &LKModelBase_Key_Inserting) boolValue];
85+
return [objc_getAssociatedObject(self, &LKModelBase_Key_Inserting) boolValue];
8686
}
8787
-(void)setDb_inserting:(BOOL)db_inserting
8888
{
@@ -624,7 +624,7 @@ -(id)db_objectWithDictionary:(NSDictionary*)dic
624624
{
625625
BOOL isNeedAddDot = NO;
626626
NSMutableString* sb = [NSMutableString stringWithFormat:@"select rowid,* from %@ where",tableName];
627-
627+
628628
NSArray* allKeys = pv.allKeys;
629629
for (NSString* key in allKeys)
630630
{
@@ -749,11 +749,11 @@ -(NSDictionary *)db_getPrimaryKeysValues
749749
id value = nil;
750750
if([property.type isEqualToString:LKSQL_Mapping_UserCalculate])
751751
{
752-
value = [self userGetValueForModel:property];
752+
value = [self userGetValueForModel:property];
753753
}
754754
else
755755
{
756-
value = [self modelGetValue:property];
756+
value = [self modelGetValue:property];
757757
}
758758
if(value)
759759
{
@@ -924,17 +924,12 @@ + (void)getSelfPropertys:(NSMutableArray *)pronames protypes:(NSMutableArray *)p
924924
unsigned int outCount = 0, i = 0;
925925
objc_property_t *properties = class_copyPropertyList(self, &outCount);
926926

927-
id respondInstance = nil;
928-
if(outCount > 0)
929-
{
930-
respondInstance = [[self alloc]init];
931-
}
932927
for (i = 0; i < outCount; i++) {
933928
objc_property_t property = properties[i];
934929
NSString *propertyName = [NSString stringWithCString:property_getName(property) encoding:NSUTF8StringEncoding];
935930

936931
//取消rowid 的插入 //子类 已重载的属性 取消插入
937-
if([propertyName isEqualToString:@"rowid"] ||
932+
if(propertyName.length == 0 || [propertyName isEqualToString:@"rowid"] ||
938933
[pronames indexOfObject:propertyName] != NSNotFound)
939934
{
940935
continue;
@@ -944,10 +939,12 @@ + (void)getSelfPropertys:(NSMutableArray *)pronames protypes:(NSMutableArray *)p
944939
///过滤只读属性
945940
if ([propertyType rangeOfString:@",R,"].length > 0 || [propertyType hasSuffix:@",R"])
946941
{
947-
NSString* setMethodString = [NSString stringWithFormat:@"set%@:",[propertyName capitalizedString]];
942+
NSString* firstWord = [[propertyName substringToIndex:1] uppercaseString];
943+
NSString* otherWord = [propertyName substringFromIndex:1];
944+
NSString* setMethodString = [NSString stringWithFormat:@"set%@%@:",firstWord,otherWord];
948945
SEL setSEL = NSSelectorFromString(setMethodString);
949946
///有set方法就不过滤了
950-
if([respondInstance respondsToSelector:setSEL] == NO)
947+
if([self instancesRespondToSelector:setSEL] == NO)
951948
{
952949
continue;
953950
}
@@ -1030,7 +1027,6 @@ + (void)getSelfPropertys:(NSMutableArray *)pronames protypes:(NSMutableArray *)p
10301027
[pronames addObject:propertyName];
10311028
[protypes addObject:propertyClassName];
10321029
}
1033-
respondInstance = nil;
10341030
free(properties);
10351031
if([self isContainParent] && [self superclass] != [NSObject class])
10361032
{

0 commit comments

Comments
 (0)