Swift is awesome.
Swift is awesome
Swift is awesome.
连接中
print("This is wild", terminator: " ")
print("world")
印刷品:
This is wild world
因此,使用终止符时,应该注意内容是否与同一行相关。
用 定制字符串可转换打印对象
struct Address {
let city: String
}
class Person {
let name = "Jack"
let addresses = [
Address(city: "Helsinki"),
Address(city: "Tampere")
]
}
extension Person: CustomStringConvertible {
var description: String {
let objectAddress = unsafeBitCast(self, to: Int.self)
return String(format: "<name: \(name) %p>", objectAddress)
}
}
let jack = Person()
print(jack)
印刷品:
<name: Jack 0x608000041c20>
可转换的
extension Person: CustomDebugStringConvertible {
var debugDescription: String {
let objectAddress = unsafeBitCast(self, to: Int.self)
let addressString = addresses.map { $0.city }.joined(separator: ",")
return String(format: "<name: \(name), addresses: \(addressString) %p>",objectAddress)
}
}