Discussion 解説
Calling this property directly is discouraged. Instead, convert an instance of any type to a string by using the String(describing:)
initializer. This initializer works with any type, and uses the custom description
property for types that conform to Custom
:
このプロパティを直接に呼び出すことは、推奨されません。代わりに、どんな型のインスタンスでも文字列へと、String(describing:)
イニシャライザを使って変換してください。このイニシャライザはどんな型とでも働きます、そしてあつらえのdescription
プロパティをCustom
に準拠する型に対して使います:
struct Point: CustomStringConvertible {
let x: Int, y: Int
var description: String {
return "(\(x), \(y))"
}
}
let p = Point(x: 21, y: 30)
let s = String(describing: p)
print(s)
// Prints "(21, 30)"
The conversion of p
to a string in the assignment to s
uses the Point
type’s description
property.
s
への代入におけるp
の文字列への変換は、Point
型のもつdescription
プロパティを使います。
Note 注意
This documentation comment was inherited from Custom
.
この文書化コメントは、Custom
から引き継がれました。