Your extension is not "generic" in the sense that it can apply to any type. It can only apply to types that have a description
property. Well, which types have a description
property? Every type that conforms to CustomStringConvertible
does!
So you should create an extension of CustomStringConvertible
:
extension CustomStringConvertible {
func print() { Swift.print(self.description) }
}
(Note that there could be a type that have a description
property, but does not conform to CustomStringConvertible
, but most types in the standard libraries aren't like this)
Truly generic extensions are something else, and is currently being proposed, i.e. not part of Swift yet.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…