Skip to content

Instantly share code, notes, and snippets.

@clarkeben
Last active October 3, 2023 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clarkeben/5c08db681e47b26fed2e68aa15855430 to your computer and use it in GitHub Desktop.
Save clarkeben/5c08db681e47b26fed2e68aa15855430 to your computer and use it in GitHub Desktop.
String-interpolation
var bobScore = "Bob has a score of \(2 * 3)"
let currentScore = 10
let userScore = "User has a score of \(currentScore)"
struct User {
var userName: String
var score: Int
}
extension String.StringInterpolation {
mutating func appendInterpolation(user: User) {
appendInterpolation("User \(user.userName) has a score of \(user.score)")
}
}
let ben = User(userName: "Ben10", score: 2)
print("\(user: ben)") ///User Ben10 has a score of 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment