-
-
Save geykel/3fc2b37477e0cfa5ecfc1c7db9003cce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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