Skip to content

Instantly share code, notes, and snippets.

@juzooda
Created March 17, 2017 22:45
Show Gist options
  • Save juzooda/3829c7455fd2f381c869e6dd1d81ee82 to your computer and use it in GitHub Desktop.
Save juzooda/3829c7455fd2f381c869e6dd1d81ee82 to your computer and use it in GitHub Desktop.
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