4 ms·
extensions let you do this with enums (as well as protocols): enum Car { case Red case Blue } extension Car { func hello() { p
by alexjarvis 11y ago
extensions let you do this with enums (as well as protocols):
enum Car {
case Red
case Blue
}
extension Car {
func hello() {
print("hello")
}
}
let x = Car.Blue
x.hello()
https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Protocols.html https://developer.apple.com/library/ios/documentation/Swift/...
edit: although you can't add a new case to the enum.
- Manishearth 11y ago> although you can't add a new case to the enum. That's the point. We all know you can add impls or extensions.