假设我有一个代码结构: struct Point { var x = 0.0 var y = 0.0}var p = Point(x: 5.0, y: 3.0)println("\(p)") 我会得到: V6AppName8Point (has 2 children) 反正有没有把它转换成自定义的东西?在Objective-C中,我相
struct Point {
var x = 0.0
var y = 0.0
}
var p = Point(x: 5.0, y: 3.0)
println("\(p)")
我会得到:
V6<AppName>8Point (has 2 children)
反正有没有把它转换成自定义的东西?在Objective-C中,我相信这已经被description()方法所覆盖,但这在这里不起作用.
是的你可以!查看 Apple docs on the Printable protocol.来自文档的示例代码:
struct MyType: Printable {
var name = "Untitled"
var description: String {
return "MyType: \(name)"
}
}
let value = MyType()
println("Created a \(value)")
// prints "Created a MyType: Untitled"
