Created
January 7, 2020 00:35
-
-
Save dagronf/2849057e85d0a856ec4f1f4af6a7dcfa to your computer and use it in GitHub Desktop.
Swift String extension to use NSString's 'bool' interpretation rules.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
extension String { | |
/// Retrieve the contents of the string as a Bool value. | |
/// | |
/// This property is true on encountering one of "Y", "y", "T", "t", or a digit 1-9—the method ignores any trailing characters. This property is false if the receiver doesn’t begin with a valid decimal text representation of a number. | |
/// | |
/// The property assumes a decimal representation and skips whitespace at the beginning of the string. It also skips initial whitespace characters, or optional -/+ sign followed by zeroes. | |
/// | |
/// See: [NSString boolValue](https://developer.apple.com/documentation/foundation/nsstring/1409420-boolvalue) | |
var boolValue: Bool { | |
return (self as NSString).boolValue | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment