Implicit Conversion of 'BOOL'(aka 'bool') to 'id' is disallowed by ARC

Varun Varahabotla picture Varun Varahabotla · Aug 3, 2015 · Viewed 13k times · Source

I am trying to transform a value of Pending/Completed to a boolean True/False value

Here is the code for that:

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;
    }];

However, I get the error: Implicit Conversion of 'BOOL'(aka 'bool') to 'id' is disallowed by ARC

When i try to set the outputValue to be YES...

What's going on here?

It should match this output:

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

Answer

Paulw11 picture Paulw11 · Aug 3, 2015

The transformationBlock accepts an input object and needs to output a different object, but BOOL is an intrinsic type, not an object type, so you can't set *output to a straight boolean value.

You can set it to an NSNumber object that wraps the Boolean value -

*output=[NSNumber numberWithBool:YES]; 

Or use the shorthand

*output=@YES;