Skip to content

Instantly share code, notes, and snippets.

@Amzd
Last active January 2, 2025 10:35
Show Gist options
  • Save Amzd/de5dd56074d4123fc602379f5a7cc56d to your computer and use it in GitHub Desktop.
Save Amzd/de5dd56074d4123fc602379f5a7cc56d to your computer and use it in GitHub Desktop.
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 }
}
#!/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