我的NSObject中有一个BOol定义为:
@property (nonatomic) BOol isOpen;
在我的reskit类中,我使用:
[mapPing addAttributeMapPingsFromDictionary:@{...... @"isOpen": @"isOpen" ......}];
使用我的iPhone4S和原装iPhone5,我的所有测试都运行了好几周.作为我在64位设备上在模拟器上测试的最后一次测试,我收到以下错误:
restkit.object_mapPing:RKMapPingOperation.m:440 Failed transformation of value at keyPath 'isOpen' to representation of type '__NSCFBoolean': Error Domain=org.restkit.RKValuetransformers.ErrorDomain Code=3002 "Failed transformation of value '1' to __NSCFBoolean: none of the 2 value transformers consulted were successful." UserInfo=0x10cba1c00 {NSLocalizedDescription=Failed transformation of value '1' to __NSCFBoolean: none of the 2 value transformers consulted were successful.,detailedErrors=("Error Domain=org.restkit.RKValuetransformers.ErrorDomain Code=3002 \"The given value is not already an instance of '__NSCFBoolean'\" UserInfo=0x10cb86d30 {NSLocalizedDescription=The given value is not already an instance of '__NSCFBoolean'}","Error Domain=org.restkit.RKValuetransformers.ErrorDomain Code=3000 \"Expected an `inputValue` of type `NSNull`,but got a `__NSCFNumber`.\" UserInfo=0x10cbeb400 {NSLocalizedDescription=Expected an `inputValue` of type `NSNull`,but got a `__NSCFNumber`.}" )}解决方法 正如Mikael所说,在64位平台上运行的RestKit存在一些小故障,阻止了从NSNumber到BOol的默认转换(反之亦然).
但是,借助RestKit Value transformers模块化架构,可以实现这一目标.因此,您只需创建一个专用的变换器类并使用RestKit默认变换器进行注册.
这就是变压器的样子:
@interface RKCustomBOoltransformer : NSObject <RKValuetransforming>+ (instancetype)defaulttransformer;@end@implementation RKCustomBOoltransformer+ (instancetype)defaulttransformer { return [RKCustomBOoltransformer new];}- (BOol)valIDatetransformationFromClass:(Class)inputValueClass toClass:(Class)outputValueClass { return ([inputValueClass isSubclassOfClass:[NSNumber class]] && [outputValueClass isSubclassOfClass:[NSNumber class]]);}- (BOol)transformValue:(ID)inputValue tovalue:(ID *)outputValue ofClass:(Class)outputValueClass error:(NSError **)error { RKValuetransformerTestinputValueIsKindOfClass(inputValue,(@[ [NSNumber class] ]),error); RKValuetransformerTestOutputValueClassIsSubclassOfClass(outputValueClass,error); if (strcmp([inputValue objCType],@encode(BOol)) == 0) { *outputValue = inputValue?@(1):@(0); } else if (strcmp([inputValue objCType],@encode(int)) == 0) { *outputValue = ([inputValue intValue] == 0) ? @(NO) : @(YES); } return YES;}@end
你这样注册:
[[RKValuetransformer defaultValuetransformer] insertValuetransformer:[RKCustomBOoltransformer defaulttransformer] atIndex:0];
在定义映射之前,请注意进行注册.
总结以上是内存溢出为你收集整理的ios – RestKit不会在64位模拟器中映射BOOL全部内容,希望文章能够帮你解决ios – RestKit不会在64位模拟器中映射BOOL所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)