I am programming in Objective-C for iOS. I would like to parse an object of type NSString into a scalar of type BOOL.
I have a value, and I know that it will either be @"YES" or @"NO", but that YES (or) NO value is NSString and I just want to change NSString into BOOL.
How can I do that?
Please answer me if you know.
Thanks for reading.
I think it's this:
BOOL boolValue = [myString boolValue];
You should probably use NSString
's -boolValue
. To quote the documentation directly:
[Returns t]he Boolean value of the receiver’s text. Returns YES on encountering one of "Y", "y", "T", "t", or a digit 1-9—the method ignores any trailing characters. Returns NO if the receiver doesn’t begin with a valid decimal text representation of a number.
That would seem to match your input cases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With