Skip to content

Instantly share code, notes, and snippets.

@geykel
Last active May 2, 2017 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geykel/3fc2b37477e0cfa5ecfc1c7db9003cce to your computer and use it in GitHub Desktop.
Save geykel/3fc2b37477e0cfa5ecfc1c7db9003cce to your computer and use it in GitHub Desktop.
// 1
protocol Base {
}
// 2
struct A : Base {
func mensajeA() -> String {
return "Soy de tipo A"
}
}
// 3
struct B : Base {
func mensajeB() -> String {
return "Soy de tipo B"
}
}
// 4
struct Pila {
// 5
private var elementos = [Base]()
// 6
mutating func poner(_ elemento: Base) {
elementos.append(elemento)
}
// 7
mutating func extraer() -> Base {
return elementos.removeLast()
}
}
// 8
var pilaA = Pila()
var a1 = A()
pilaA.poner(a1)
print((pilaA.extraer() as! A).mensajeA())
// 9
var pilaB = Pila()
var b1 = B()
pilaB.poner(b1)
print((pilaB.extraer() as! B).mensajeB())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment