8

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) 
}
Varun Varahabotla
  • 548
  • 2
  • 7
  • 16

1 Answers1

21

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;
Paulw11
  • 108,386
  • 14
  • 159
  • 186