Last active
January 2, 2025 10:35
-
-
Save Amzd/de5dd56074d4123fc602379f5a7cc56d to your computer and use it in GitHub Desktop.
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
extension String? { | |
/// 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. | |
var yN: Bool { if let self { NSString(string: self).boolValue } else { false } } | |
/// This property is true when it is empty (or nil) or when yN is true | |
var Yn: Bool { (self?.isEmpty ?? true) || yN } | |
} |
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
#!/usr/bin/env swift | |
import Foundation | |
print("Are you sure? [y/N]") | |
guard readLine().yN else { exit(0) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment