Created
July 28, 2024 07:07
-
-
Save Enchan1207/9301516f0268f9615bd63169e98e0930 to your computer and use it in GitHub Desktop.
Swiftの文字列補間を使っていい感じにフォーマットを埋め込む
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(_ value: CVarArg, format: String) { | |
appendLiteral(.init(format: format, value)) | |
} | |
} | |
// Usage | |
print("π = \(pi)") // π = 3.141592653589793 | |
print("π = \(pi, format: "%.2f")") // π = 3.14 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment