Skip to content

Commit

Permalink
fix x86_64
Browse files Browse the repository at this point in the history
  • Loading branch information
shjborage committed Apr 29, 2014
1 parent aec1749 commit 2cfa4a8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
4 changes: 2 additions & 2 deletions AutoNSCoding.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "AutoNSCoding.podspec"
s.version = "0.1.1"
s.version = "0.1.2"
s.summary = "Make NSCoding protocol automatic."

s.description = <<-DESC
Expand All @@ -16,6 +16,6 @@ Pod::Spec.new do |s|
s.author = { "Eric" => "shjborage@icloud.com" }
s.social_media_url = "http://twitter.com/Eric_shj"
s.platform = :ios, '2.0'
s.source = { :git => "https://github.com/shjborage/AutoNSCoding.git", :tag => "v0.1.1" }
s.source = { :git => "https://github.com/shjborage/AutoNSCoding.git", :tag => "v0.1.2" }
s.source_files = '*.{h,m}'
end
38 changes: 25 additions & 13 deletions NSObject+NSCoding.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ - (void)encodeAutoWithCoder:(NSCoder *)aCoder class:(Class)class
Method mt = class_getInstanceMethod(class, selector);
if (mt != NULL) {
NSString *returnType = [class getMethodReturnType:mt];
if ([returnType isEqualToString:@"i"] || [returnType isEqualToString:@"q"]) {
if ([returnType isEqualToString:@"i"] ||
[returnType isEqualToString:@"q"] ||
[returnType isEqualToString:@"Q"])
{
int intValue = ((int(*)(id, Method))method_invoke)(self, mt);
#if kNSCodingDebugLoging
NSLog(@"Encode %@ %@ int value:%d", NSStringFromClass(class), name, intValue);
Expand All @@ -55,14 +58,18 @@ - (void)encodeAutoWithCoder:(NSCoder *)aCoder class:(Class)class
NSLog(@"Encode %@ %@ int value:%d", NSStringFromClass(class), name, intValue);
#endif
[aCoder encodeInteger:intValue forKey:name];
} else if ([returnType isEqualToString:@"f"] || [returnType isEqualToString:@"d"]) {
} else if ([returnType isEqualToString:@"f"] ||
[returnType isEqualToString:@"d"])
{
double doubleValue = ((double(*)(id, Method))method_invoke)(self, mt);
#if kNSCodingDebugLoging
NSLog(@"Encode %@ %@ double value:%.f", NSStringFromClass(class), name, doubleValue);
#endif

[aCoder encodeDouble:doubleValue forKey:name];
} else if ([returnType isEqualToString:@"c"]) { // char 一般为BOOL, property不用char即可
} else if ([returnType isEqualToString:@"c"] ||
[returnType isEqualToString:@"B"])
{ // char 一般为BOOL, property不用char即可
BOOL boolValue = ((char(*)(id, Method))method_invoke)(self, mt);
#if kNSCodingDebugLoging
NSLog(@"Encode %@ %@ BOOL value:%d", NSStringFromClass(class), name, boolValue);
Expand Down Expand Up @@ -106,19 +113,22 @@ - (void)decodeAutoWithAutoCoder:(NSCoder *)aDecoder class:(Class)class
Method mt = class_getInstanceMethod(class, selector);
if (mt != NULL) {
NSString *argumentType = [class getMethodArgumentType:mt index:2];
if ([argumentType isEqualToString:@"i"] || [argumentType isEqualToString:@"q"]) {
int intValue = [aDecoder decodeIntegerForKey:name];
void (*method_invokeTyped)(id self, Method mt, int value) = (void*)method_invoke;
if ([argumentType isEqualToString:@"i"] ||
[argumentType isEqualToString:@"q"] ||
[argumentType isEqualToString:@"Q"])
{
NSInteger intValue = [aDecoder decodeIntegerForKey:name];
void (*method_invokeTyped)(id self, Method mt, NSInteger value) = (void*)method_invoke;
method_invokeTyped(self, mt, intValue);
#if kNSCodingDebugLoging
NSLog(@"Decode %@ %@ intValue:%d", NSStringFromClass(class), name, intValue);
NSLog(@"Decode %@ %@ intValue:%ld", NSStringFromClass(class), name, (long)intValue);
#endif
} else if ([argumentType isEqualToString:@"I"]) {
unsigned intValue = [aDecoder decodeIntegerForKey:name];
void (*method_invokeTyped)(id self, Method mt, unsigned value) = (void*)method_invoke;
method_invokeTyped(self, mt, intValue);
NSUInteger uIntValue = [aDecoder decodeIntegerForKey:name];
void (*method_invokeTyped)(id self, Method mt, NSUInteger value) = (void*)method_invoke;
method_invokeTyped(self, mt, uIntValue);
#if kNSCodingDebugLoging
NSLog(@"Decode %@ %@ unsigned intValue:%d", NSStringFromClass(class), name, intValue);
NSLog(@"Decode %@ %@ unsigned intValue:%lu", NSStringFromClass(class), name, (unsigned long)uIntValue);
#endif
} else if ([argumentType isEqualToString:@"f"] || [argumentType isEqualToString:@"d"]) {
double doubleValue = [aDecoder decodeDoubleForKey:name];
Expand All @@ -127,7 +137,9 @@ - (void)decodeAutoWithAutoCoder:(NSCoder *)aDecoder class:(Class)class
#if kNSCodingDebugLoging
NSLog(@"Decode %@ %@ doubleValue:%f", NSStringFromClass(class), name, doubleValue);
#endif
} else if ([argumentType isEqualToString:@"c"]) { // char 一般为BOOL, property不用char即可
} else if ([argumentType isEqualToString:@"c"] ||
[argumentType isEqualToString:@"B"])
{ // char 一般为BOOL, property不用char即可
BOOL boolValue = [aDecoder decodeBoolForKey:name];
void (*method_invokeTyped)(id self, Method mt, BOOL value) = (void*)method_invoke;
method_invokeTyped(self, mt, boolValue);
Expand Down Expand Up @@ -182,7 +194,7 @@ + (NSString *)getMethodArgumentType:(Method)mt index:(NSInteger)index
{
char dstType[10] = {0};
size_t dstTypeLen = 10;
method_getArgumentType(mt, index, dstType, dstTypeLen);
method_getArgumentType(mt, (unsigned)index, dstType, dstTypeLen);
return [NSString stringWithUTF8String:dstType];
}

Expand Down

0 comments on commit 2cfa4a8

Please sign in to comment.