Created
March 17, 2017 22:45
-
-
Save juzooda/3829c7455fd2f381c869e6dd1d81ee82 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import UIKit | |
protocol StackType { | |
func example() | |
} | |
struct SimpleStack<T: StackType> { | |
private var list:[T] = [] | |
mutating func push(item: T){ | |
list.append(item) | |
} | |
mutating func pop(){ | |
let lastElement = list.last | |
lastElement?.example() | |
list.removeLast() | |
} | |
} | |
struct StackView: StackType { | |
func example() { | |
//Do something important | |
} | |
} | |
var stack = SimpleStack<StackView>() | |
let view1 = StackView() | |
let view2 = StackView() | |
stack.push(item: view1) | |
stack.push(item: view2) | |
func swap<Element>(first: inout Element, second: inout Element){ | |
let tempFirst = first | |
first = second | |
second = tempFirst | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment