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

Var*_*tla 8 objective-c ios 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;
    }];
Run Code Online (Sandbox Code Playgroud)

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

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

这里发生了什么?

它应匹配此输出:

{ 
   “IsCompleted”: true (nullable),
   “Desc”: null (“new description” on edit) 
}
Run Code Online (Sandbox Code Playgroud)

Pau*_*w11 15

transformationBlock接受一个输入的对象,需要输出一个不同的对象,但BOOL是本征型,而不是一个对象类型,所以可以不设置*output于直布尔值.

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

*output=[NSNumber numberWithBool:YES]; 
Run Code Online (Sandbox Code Playgroud)

或者使用速记

*output=@YES;
Run Code Online (Sandbox Code Playgroud)