将' BOOL'(又名' bool')隐式转换为' id' ARC不允许这样做

时间:2015-08-03 21:35:54

标签: ios objective-c restkit

我正在尝试将Pending / Completed的值转换为布尔值True / False值

以下是代码:

RKValueTransformer *transformer = [RKBlockValueTransformer valueTransformerWithValidationBlock:^BOOL(__unsafe_unretained Class sourceClass, __unsafe_unretained Class destinationClass) {
        return ([sourceClass isSubclassOfClass:[NSNumber class]]);
    } transformationBlock:^BOOL(NSNumber *inputValue, __autoreleasing id *outputValue, __unsafe_unretained Class outputClass, NSError *__autoreleasing *error) {
        // validate the input
        RKValueTransformerTestInputValueIsKindOfClass(inputValue, [NSNumber class], error);
        if([inputValue isEqualToNumber:@(Completed)]) {
            *outputValue = YES;
        } else if([inputValue isEqualToNumber:@(Pending)]){
            *outputValue = FALSE;
        }
        return YES;
    }];

但是,我收到错误:Implicit Conversion of 'BOOL'(aka 'bool') to 'id' is disallowed by ARC

当我尝试将outputValue设置为YES ...

这里发生了什么?

它应匹配此输出:

{ 
   “IsCompleted”: true (nullable),
   “Desc”: null (“new description” on edit) 
}

1 个答案:

答案 0 :(得分:14)

transformationBlock接受输入对象并需要输出不同的对象,但BOOL是内部类型,而不是对象类型,因此您无法将*output设置为直接布尔值值。

您可以将其设置为包含布尔值的NSNumber对象 -

*output=[NSNumber numberWithBool:YES]; 

或使用简写

*output=@YES;
相关问题