Skip to content

Instantly share code, notes, and snippets.

@Enchan1207
Created July 28, 2024 07:07
Show Gist options
  • Save Enchan1207/9301516f0268f9615bd63169e98e0930 to your computer and use it in GitHub Desktop.
Save Enchan1207/9301516f0268f9615bd63169e98e0930 to your computer and use it in GitHub Desktop.
Swiftの文字列補間を使っていい感じにフォーマットを埋め込む
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