How to parse a boolean value in NSString

I have the following method that does some string assembly, but unfortunately I had a problem parsing a boolean in my NSString.

The following code:

- (void)setToolOutput:(int) outputNumber state: (BOOL) value {
    NSString *str =  [NSString stringWithFormat:@"this=%i is=%c",outputNumber,value];
    NSData* data = [str dataUsingEncoding:NSUTF8StringEncoding];
    [OutputStream write:[data bytes] maxLength:[data length]];
    NSLog(@"%@", str);
}

I tried to parse it using %cfor char and %sas a character string. Both methods output my boolean as question mark turned upside down.

EDIT: I want him to understand how Trueor False.

+3
source share
2 answers

Boolean is basically an integer, so you can use %ito get the decimal representation. Usually you want:

NSString *booleanString = (value) ? @"True" : @"False";

+31
source

EDIT: Sorry for my mistake

boolean, , "True" "False"

        NSString *target = @"";
        if(tmp)
        {
            target = @"True";
        }
        else {
            target = @"False";
        }

        // use target variable as you prefer
-2

All Articles