Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
class Fruit {}
class Apple: Fruit {}
class Orange: Fruit {}
class Basket<T> where T: Fruit
var items: [T] = []
func add(_ item: T) {
func addItem<T>(_ basket: Basket<T>, _ item: T) where T: Fruit
func logType(fruit: Fruit) {
print(type(of: fruit))
var basket = Basket<Fruit>()
addItem(basket, Apple())
addItem(basket, Orange())
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.