Jak mogę zmodyfikować tekstowe dane wyjściowe, które są wyświetlane w interpolacji ciągów?
PrintableProtokół wygląda najbardziej oczywiste, ale to zignorował zarówno String interpolacji podczas drukowania instancji, np:
struct Point : Printable
{
var x = 0
var y = 0
var description : String {
return "(\(x), \(y))"
}
func toString() -> String {
return description
}
}
Podobnie toString()konwencja nie ma żadnego skutku:
var p = Point(x: 10, y: 20)
println(p) // V11lldb_expr_05Point (has 2 children)
println("\(p)") // V11lldb_expr_05Point (has 2 children)
println(p.description) // (10, 20)
println("\(p.description)") // (10, 20)
Zachowanie jest znowu inne w PlayGround, który używa własnej reprezentacji String dla struktur, tj .:
p // {x 10, y 20}
Czy istnieje sposób, aby zmienić sposób wyświetlania instancji?



