Skip to content

Instantly share code, notes, and snippets.


Pasanpr/associatedTypes.swift Secret

Created Feb 6, 2017
What would you like to do?
protocol Animal {
associatedtype Food
func eat(_ food: Food)
struct Kibble {}
class Cat: Animal {
func eat(_ food: Kibble) {
// code
struct DogFood {}
class Dog: Animal {
func eat(_ food: DogFood) {
let cat = Cat()
let dog = Dog()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.