A convenient shortcut of [NSString stringWithFormat:] for boolean values.
/** Convert a bool to its string representation.
Param "mode" identifies the conversion method as follow:
mode = 0: "YES", "NO"
mode = 1: "TRUE", "FALSE"
mode = 2: "1", "0"
@param b Boolean value to convert.
@param mode Type of conversion method and therefore also the result type.
@return Returns the string value of the boolean value base on "mode" conversion method.
@see stringFromInt:
@see stringFromFloat:usingSeparatorForDecimal:
@see boolFromString:
*/
+ (NSString *)stringFromBool:(BOOL)b ofType:(NSInteger)mode {
switch (mode) {
case 0:
return (b ? @"YES" : @"NO" );
break;
case 1:
return (b ? @"TRUE" : @"FALSE" );
break;
case 2:
return (b ? @"1" : @"0" );
break;
default:
LogError(@"Type not detected: %d", mode);
return @"Error";
break;
}
}
Download the ready-for-use source file (.m) of BOOL to NSString
No comments:
Post a Comment