Skip to main content

toString 相当のもの

CustomStringConvertible プロトコルで description プロパティを実装する。

swift
struct X: CustomStringConvertible {
// MARK: - CustomStringConvertible
var description: String {
return "xxx"
}
}

CustomStringConvertible を指定すると print(x)print("\(x)")description が出るようになる

appendInterpolation に対応する?

Swift 5 で String Interpolation をカスタマイズする