Skip to content

Instantly share code, notes, and snippets.

@koher
Created May 14, 2017 22:01
Show Gist options
  • Save koher/d62e4dbafe0687f1a708b53b5ed21cd4 to your computer and use it in GitHub Desktop.
Save koher/d62e4dbafe0687f1a708b53b5ed21cd4 to your computer and use it in GitHub Desktop.
class Animal {}
class Cat: Animal {}
let cats: Array<Cat> = [Cat()]
let animals: Array<Animal> = cats // OK
let cat: Optional<Cat> = .some(Cat())
let animal: Optional<Animal> = cat // OK
struct Box<Value> {
var value: Value
}
let catBox: Box<Cat> = Box(value: Cat())
let animalBox: Box<Animal> = catBox // error: cannot convert value of type 'Box<Cat>' to specified type 'Box<Animal>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment