Browsing Swift's library code I've found:
extension T! : Printable {
var description: String { get }
}
The snippet seems to extend all types with the 'description' field. When I try to do the same thing in my code, I get error:
example.swift:10:11: Non-nominal type 'T!' cannot be extended
protocol MyProtocol {
// ...
}
extension T! : MyProtocol { // error: Non-nominal...
// ...
}
There are similar questions at:
- How can I extend typed Arrays in Swift?
- What's the difference between Optional<T> and optional types in Swift? Extending Optional to carry error information?
But they fail to address:
- What's going on here? Why is the library code okay, but my code... not?
- Is it possible to all types or all types that conform to a specific protocol?