Created
August 11, 2015 15:41
-
-
Save NeoTeo/8ff16e0db9778b38cd91 to your computer and use it in GitHub Desktop.
Using associated types in protocols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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