Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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) 
}
like image 225
Varun Varahabotla Avatar asked Aug 03 '15 21:08

Varun Varahabotla


1 Answers

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;
like image 172
Paulw11 Avatar answered Nov 02 '22 11:11

Paulw11