Hacker News new | ask | show | jobs
by alexjarvis 3840 days 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/...

edit: although you can't add a new case to the enum.

1 comments

> although you can't add a new case to the enum.

That's the point. We all know you can add impls or extensions.