Skip to content

Instantly share code, notes, and snippets.

View Amzd's full-sized avatar
🚀

Casper Zandbergen Amzd

🚀
View GitHub Profile
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 }
}
@Amzd
Amzd / Version.swift
Last active February 24, 2025 20:45
Semantic Version decoding in Swift. Does not validate the identifier.
/// https://gist.github.com/Amzd/93f2e7b4712242ec4e17476146f528a2
public struct Version: Codable {
public var major: UInt
public var minor: UInt
public var patch: UInt
public var identifier: String?
public var stringValue: String {
"\(major).\(minor).\(patch)" + (identifier.flatMap { "-\($0)" } ?? "")
}