我试图将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) NSString *expectedURL = [NSString stringWithFormat:@"https://%@:%ld/%@"];
什么做%@和%ld什么意思呢?