Created
June 2, 2023 01:07
-
-
Save natecook1000/66e641c961dc938157cfc7acb9b3d25e to your computer and use it in GitHub Desktop.
This file contains 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.StringInterpolation { | |
mutating func appendInterpolation<T>(_ value: T?, default: @autoclosure () -> String) { | |
self.appendLiteral(value.map(String.init(describing:)) ?? `default`()) | |
} | |
} | |
let num = Int("21") | |
print("The number is: \(num, default: "<invalid>")") | |
// The number is: 21 | |
let num2 = Int("asd") | |
print("The number is: \(num2, default: "<invalid>")") | |
// The number is: <invalid> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment