1.计算器的二元运算:
switch operation{
case "×": performOperation { $0 * $1 }
case "÷": performOperation { $1 / $0 }
case "+" : performOperation { $0 + $1 }
case "−" : performOperation { $1 - $0 }
case "√" : performO { sqrt($0) }
default: break
}
调用 switch方法,定义performOperation
func performOperation(operation:(Double, Double) -> Double)
{
if operandStack.count >= 2{
displayValue = operation(operandStack.removeLast() , operandStack.removeLast() )
enter()}
}
定义performO
func performO(operation:Double -> Double){
if operandStack.count >= 1 {
displayValue = operation(operandStack.removeLast())
enter()}
}
需注意:在斯坦福老爷子的视频中在后一个方法可以中以同样的performOperation定义,而在Xcode7.0中不能以同样的名字定义Func。
同时,在session2中,探讨了Autolayout 自动布局,这对于同一应用在不同尺寸设备中的兼容性意义重大;
2.MVC模式
初次一览MVC模式
Model -- View -- Controller
Model = What your application is( but not how it is displayed)
View = your controller's minions
Controller = How your Model is presented to the user (UI logic)
Model (模型)是业务逻辑,用于具体实现程序相应功能
View (视图)是页面展示
Controller(控制器) 是起到不同层次的组织作用
需要注意:在MVC模式中,Model和View之间不能直接通讯,需要通过Controller来做中间调度。