From f2df95dc14749d72aac21be2b7fc34715d807238 Mon Sep 17 00:00:00 2001 From: Robert Manea Date: Mon, 29 Sep 2014 13:09:52 +0200 Subject: [PATCH 1/3] Ignore propertied introduced with iOS 8 --- NSObject+NSCoding.m | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/NSObject+NSCoding.m b/NSObject+NSCoding.m index d64f433..6ad5835 100644 --- a/NSObject+NSCoding.m +++ b/NSObject+NSCoding.m @@ -38,7 +38,12 @@ - (void)encodeAutoWithCoder:(NSCoder *)aCoder class:(Class)class for (int i = 0; i < outCount; i++) { objc_property_t property = pt[i]; NSString *name = [NSString stringWithUTF8String:property_getName(property)]; - + + // Ignore Properties indrocuded with iOS 8 + if ([@[@"description", @"debugDescription", @"superclass"] containsObject:name]) { + continue; + } + SEL selector = NSSelectorFromString(name); Method mt = class_getInstanceMethod(class, selector); if (mt != NULL) { @@ -108,7 +113,12 @@ - (void)decodeAutoWithAutoCoder:(NSCoder *)aDecoder class:(Class)class for (int i = 0; i< outCount; i++) { objc_property_t property = pt[i]; NSString *name = [NSString stringWithUTF8String:property_getName(property)]; - + + // Ignore Properties indrocuded with iOS 8 + if ([@[@"description", @"debugDescription", @"superclass"] containsObject:name]) { + continue; + } + SEL selector = NSSelectorFromString([class getSetMethodName:name]); Method mt = class_getInstanceMethod(class, selector); if (mt != NULL) { From 9ff16792a8a87f8515b090ab1b9c5a531c51cc6c Mon Sep 17 00:00:00 2001 From: Robert Manea Date: Mon, 29 Sep 2014 13:13:37 +0200 Subject: [PATCH 2/3] fixed typo --- NSObject+NSCoding.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NSObject+NSCoding.m b/NSObject+NSCoding.m index 6ad5835..4df6f8a 100644 --- a/NSObject+NSCoding.m +++ b/NSObject+NSCoding.m @@ -39,7 +39,7 @@ - (void)encodeAutoWithCoder:(NSCoder *)aCoder class:(Class)class objc_property_t property = pt[i]; NSString *name = [NSString stringWithUTF8String:property_getName(property)]; - // Ignore Properties indrocuded with iOS 8 + // Ignore properties indrocuded with iOS 8 if ([@[@"description", @"debugDescription", @"superclass"] containsObject:name]) { continue; } @@ -114,7 +114,7 @@ - (void)decodeAutoWithAutoCoder:(NSCoder *)aDecoder class:(Class)class objc_property_t property = pt[i]; NSString *name = [NSString stringWithUTF8String:property_getName(property)]; - // Ignore Properties indrocuded with iOS 8 + // Ignore properties indrocuded with iOS 8 if ([@[@"description", @"debugDescription", @"superclass"] containsObject:name]) { continue; } From e451c440132d5e03f5564b0b313d3e8a048186a3 Mon Sep 17 00:00:00 2001 From: Robert Manea Date: Tue, 30 Sep 2014 09:04:58 +0200 Subject: [PATCH 3/3] Extracted property inclusion logic into method --- NSObject+NSCoding.m | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/NSObject+NSCoding.m b/NSObject+NSCoding.m index 4df6f8a..d04a072 100644 --- a/NSObject+NSCoding.m +++ b/NSObject+NSCoding.m @@ -39,8 +39,7 @@ - (void)encodeAutoWithCoder:(NSCoder *)aCoder class:(Class)class objc_property_t property = pt[i]; NSString *name = [NSString stringWithUTF8String:property_getName(property)]; - // Ignore properties indrocuded with iOS 8 - if ([@[@"description", @"debugDescription", @"superclass"] containsObject:name]) { + if (![self shouldEncodePropertyName:name]) { continue; } @@ -114,8 +113,7 @@ - (void)decodeAutoWithAutoCoder:(NSCoder *)aDecoder class:(Class)class objc_property_t property = pt[i]; NSString *name = [NSString stringWithUTF8String:property_getName(property)]; - // Ignore properties indrocuded with iOS 8 - if ([@[@"description", @"debugDescription", @"superclass"] containsObject:name]) { + if (![self shouldEncodePropertyName:name]) { continue; } @@ -192,6 +190,15 @@ - (void)decodeAutoWithAutoCoder:(NSCoder *)aDecoder #pragma mark - private +- (BOOL)shouldEncodePropertyName:(NSString *)name { + // Ignore properties indrocuded with iOS 8 + if ([@[@"description", @"debugDescription", @"superclass"] containsObject:name]) { + return NO; + } + + return YES; +} + + (NSString *)getMethodReturnType:(Method)mt { char dstType[10] = {0};