Restkit:methodSignatureForSelector在RKMappingOperation中与EXC_BAD_ACCESS崩溃

时间:2014-07-07 11:36:06

标签: restkit-0.20

在文件RKMappingOperation中有方法

- (NSMethodSignature *)methodSignatureForSelector:(SEL)selector
{
    return [self.object methodSignatureForSelector:selector];
}

在iPhone5上触发异常,但应用程序继续运行。但在iPhone4S上,应用程序崩溃了EXC_BAD_ACCESS。

enter image description here enter image description here

我认为异常是按照文档中的说明处理的:

引发NSInvalidArgumentException。在您的具体子类中重写此方法,以便为给定的选择器和代理对象所代表的类返回正确的NSMethodSignature对象。

日志文件:

T restkit.object_mapping:RKMappingOperation.m:862 Performing mapping operation: <RKMappingOperation 0x181e1960> for 'TSNDecimal' object. Mapping values from object 10 to object <TSNDecimal: 0x18004bc0> (entity: TSNDecimal; id: 0x1819dcb0 <x-coredata:///TSNDecimal/t507A4693-CB2E-4194-966A-00BA8AD5CC70391> ;
    data: {
    number = 0;
    responseName = nil;
    sortId = 0;
    ticket = nil;
}) with object mapping (null)
2014-07-07 13:17:50.194 VZN Mobile[440:8f0f] D restkit.object_mapping:RKPropertyInspector.m:131 Cached property inspection for Class 'TSNDecimal': {
number =     {
    isPrimitive = 0;
    keyValueCodingClass = NSDecimalNumber;
    name = number;
};
responseName =     {
    isPrimitive = 0;
    keyValueCodingClass = NSString;
    name = responseName;
};
sortId =     {
    isPrimitive = 0;
    keyValueCodingClass = NSNumber;
    name = sortId;
};
sortIdValue =     {
    isPrimitive = 1;
    keyValueCodingClass = NSNumber;
    name = sortIdValue;
};
ticket =     {
    isPrimitive = 0;
    keyValueCodingClass = TSNTicketApiTO;
    name = ticket;
};

}     2014-07-07 13:17:50.194 VZN Mobile [440:9f07] T restkit.object_mapping:RKMappingOperation.m:440在keyPath&#39;(null)&#39;处找到可转换的值。从班级转变__ NSCFNumber&#39;到#NSDecimalNumber&#39;     2014-07-07 13:17:50.204 VZN Mobile [440:9f07] self.object:10

1 个答案:

答案 0 :(得分:0)

谢谢你的评论。实际上它是由Restkit中的错误代码将NSDecimalNumber转换为NSNumber引起的。 RKValueTransformers.m中有一个方法:

+ (instancetype)decimalNumberToNumberValueTransformer
{
    ....
    ....
    RKValueTransformerTestOutputValueClassIsSubclassOfClass(outputValueClass, (@[ [NSNumber class], [NSDecimalNumber class]]), error);
    if ([inputValue isKindOfClass:[NSNumber class]]) {
        *outputValue = [NSDecimalNumber decimalNumberWithDecimal:[inputValue decimalValue]];
    } else if ([inputValue isKindOfClass:[NSDecimalNumber class]]) {
        *outputValue = inputValue;
    }
    return YES;
}];
}

条件必须以这种方式交换:

    if ([inputValue isKindOfClass:[NSDecimalNumber class]]) {
        *outputValue = [NSDecimalNumber decimalNumberWithDecimal:[inputValue decimalValue]];
    } else if ([inputValue isKindOfClass:[NSNumber class]]) {
        *outputValue = inputValue;
    }

然后代码没有崩溃,它正如作者最初所假设的那样工作。