Reputation: 2724
I have a bool value associated with a call I want to pass out of my iOS program as a string. I have tried the following:
NSString *connectedString = [self.selectedBeacon.isConnected stringValue];
But I'm not getting anything out.
Can someone please correct me?
Upvotes: 4
Views: 5938
Reputation: 5467
Converting Bool To String Swift 3 / Swift 4
let boolValue = true
print (String(boolValue))
Log
true
Upvotes: 4
Reputation: 1225
If isConnected
is a BOOL
type it shouldn't even compile. If it's NSNumber
you should get "1" or "0".
Do you want "YES" to "NO" string? Solution:
A) If a BOOL type:
NSString *connectedString = self.selectedBeacon.isConnected ? @"YES" : @"NO";
B) If NSNumber
add a category method to this class like:
- (NSString *)boolValueString {
// if this contains BOOL value
return [self boolValue] ? @"YES" : @"NO";
}
Upvotes: 5