Skip to content

Instantly share code, notes, and snippets.

@Happytreat
Created May 13, 2020 04:33
Show Gist options
  • Save Happytreat/311251c3923d164231cd495f8afd710c to your computer and use it in GitHub Desktop.
Save Happytreat/311251c3923d164231cd495f8afd710c to your computer and use it in GitHub Desktop.
lost type relationships - with Self
/**
* Example from: Protocol-oriented Programming in Swift - WWDC 2015
* https://developer.apple.com/videos/play/wwdc2015/408/
*/
protocol Ordered {
func precedes(other: Self) -> Bool
}
// value type struct
struct Number: Ordered {
var value: Double = 0
// we can now use Number: no more lost type
override func precedes(other: Number) -> Bool {
return self.value < other.value
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment