Say I have a code struct of:
struct Point {
var x = 0.0
var y = 0.0
}
var p = Point(x: 5.0, y: 3.0)
println("\(p)")
I will get:
V6<AppName>8Point (has 2 children)
Is there anyway to convert this into something custom? In Objective-C I believe this was covered with the description()
method, but that isn't working here.
Yes, you can! Check out the Apple docs on the Printable protocol.
Example code from the docs:
struct MyType: Printable {
var name = "Untitled"
var description: String {
return "MyType: \(name)"
}
}
let value = MyType()
println("Created a \(value)")
// prints "Created a MyType: Untitled"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With