1.計(jì)算器的二元運(yùn)算:
switch operation{
case? "×":? performOperation { $0 * $1 }
case? "÷":? performOperation { $1 / $0 }
case? "+" :? performOperation { $0 + $1 }
case? "?" :? performOperation { $1 - $0 }
case? "√" :? performO { sqrt($0) }
default: break
}
調(diào)用 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()}
}
需注意:在斯坦福老爺子的視頻中在后一個(gè)方法可以中以同樣的performOperation定義票灰,而在Xcode7.0中不能以同樣的名字定義Func添怔。
同時(shí)屑柔,在session2中魄揉,探討了Autolayout 自動(dòng)布局,這對(duì)于同一應(yīng)用在不同尺寸設(shè)備中的兼容性意義重大拥褂;
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 (模型)是業(yè)務(wù)邏輯赁咙,用于具體實(shí)現(xiàn)程序相應(yīng)功能
View (視圖)是頁(yè)面展示
Controller(控制器) 是起到不同層次的組織作用
需要注意:在MVC模式中,Model和View之間不能直接通訊照藻,需要通過(guò)Controller來(lái)做中間調(diào)度袜啃。