Skip to content

Instantly share code, notes, and snippets.

@thexande
Created August 19, 2019 16:48
Show Gist options
  • Save thexande/1f3b33ba902464f9f345bafa9ebc6383 to your computer and use it in GitHub Desktop.
Save thexande/1f3b33ba902464f9f345bafa9ebc6383 to your computer and use it in GitHub Desktop.
Using emojis as class names.
import Foundation
protocol JuiceContaining {
var volume: Double { get }
var juiceRatio: Double { get }
}
protocol DrinkProducing {
var drinkVolume: Double { get }
}
extension DrinkProducing where Self: FruitContaining {
var drinkVolume: Double {
return fruit.volume * fruit.juiceRatio
}
}
protocol FruitContaining {
var fruit: JuiceContaining { get }
}
final class ๐Ÿ‰: NSObject, JuiceContaining {
let volume: Double = 3
let juiceRatio: Double = 0.33
}
final class ๐Ÿน<Fruit: NSObject & JuiceContaining>: FruitContaining, DrinkProducing {
var fruit: JuiceContaining = Fruit()
}
let watermellonDrink = ๐Ÿน<๐Ÿ‰>()
print(watermellonDrink.drinkVolume) // => 0.99
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment