RestKit:BOOL的值 [英] RestKit: Values to BOOL
问题描述
我有 NS_ENUM
,其中包含核对清单的状态。这两个属性是待定
和已完成
。
I have an NS_ENUM
that holds the status of a checklist. The two properties are Pending
and Completed
.
typedef NS_ENUM(NSUInteger,ChecklistStatus){待定,已完成};
我正在尝试获取状态并映射到到真/假值。我正在使用的方法是通过RKValueTransformer。
I am trying to take the status and map that to a true/false value. The method i'm doing this with is via RKValueTransformer.
以下是代码:
+(RKValueTransformer *)checklistStatusToBooleanTransformer
{
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 isEqual:@(Completed)]) {
*outputValue = [NSNumber numberWithBool:YES];
} else {
*outputValue = [NSNumber numberWithBool:YES];
}
return YES;
}];
return transformer;
}
我无法将输出值显式地转换为BOOL,所以我真的迷失了我应该在这里做什么。
I'm not able to explicitly cast my output value as a BOOL, so i'm really lost as to what I should do here.
任何帮助都将不胜感激!
Any help would be greatly appreciated!
推荐答案
您无法显式转换,因为 BOOL
不是基本类型。检查所需的输出是否为字符串false/true而不是t / f的实际值
You can't explicitly convert, since BOOL
isn't a primitive type. Check if the desired output is a string "false"/"true" instead of actualy values of t/f
这篇关于RestKit:BOOL的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!