N0xus
N0xus

Reputation: 2724

iOS convert bool value to string

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

Answers (2)

Md. Ibrahim Hassan
Md. Ibrahim Hassan

Reputation: 5467

Converting Bool To String Swift 3 / Swift 4

let boolValue = true
print (String(boolValue))

Log

true

Upvotes: 4

Maciej Oczko
Maciej Oczko

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

Related Questions