Skip to content

Instantly share code, notes, and snippets.

@AppleCEO
Created June 18, 2019 03:18
Show Gist options
  • Select an option

  • Save AppleCEO/53ded3ecb6b3c6beb0c7b723559cc315 to your computer and use it in GitHub Desktop.

Select an option

Save AppleCEO/53ded3ecb6b3c6beb0c7b723559cc315 to your computer and use it in GitHub Desktop.
CustomStringConvertible example to class
class Point: CustomStringConvertible {
let x: Int, y: Int
var description: String {
return "(\(x), \(y))"
}
init(x: Int, y: Int) {
self.x = x
self.y = y
}
}
let p = Point(x: 21, y: 30)
let s = String(describing: p)
print(s)
print(p)
// Prints "(21, 30)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment