Skip to content

Instantly share code, notes, and snippets.

@NeoTeo
Created August 11, 2015 15:41
Show Gist options
  • Select an option

  • Save NeoTeo/8ff16e0db9778b38cd91 to your computer and use it in GitHub Desktop.

Select an option

Save NeoTeo/8ff16e0db9778b38cd91 to your computer and use it in GitHub Desktop.
Using associated types in protocols
import Cocoa
protocol ThingId { }
protocol Thing {
typealias IdType
func getId() -> IdType
}
struct MyThingId: ThingId { }
struct MyThing: Thing {
typealias IdType = MyThingId
func getId() -> MyThingId {
return MyThingId()
}
}
let aThing = MyThing()
aThing.getId()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment