IOS-노트 2(클로즈업 적용)

1558 단어
<span style="font-size:10px;">@IBActionfunc operate(sender:UIButton) {
        let operation=sender.currentTitle!
        if !firstType{
            enter()
        }
        switch operation{
        case "✕" :performOperation(multiply)//       
        case"÷" :performOperation({(op1:Double,op2:Double)->Doubleinreturn op2/op1})//closure
        case"+" :performOperation({(op1,op2)inreturn op1+op2})//             ,      
                //performOperation({(op1,op2) in op1+op2})       //               ,    return   
                //performOperation({$0+$1})                     //          ,swift     $0,$1,$2...
                //performOperation() {$0+$1}          //                   ,           ,               ,         
                //performOperation {$0+$1}                  //         ,         
        case"-" :performOperation {$1-$0}
        case"⌥" :performOperation {sqrt($0)}
        default: break
        }
    }
    func performOperation(operation:(Double,Double) ->Double){
        ifoperandStack.count >=2 {
           displayValue=operation(operandStack.removeLast(),operandStack.removeLast())
            enter()
        }
    }
    privatefunc performOperation(operation:Double ->Double){
        ifoperandStack.count >=1 {
            displayValue=operation(operandStack.removeLast())
            enter()
        }
    }
    func multiply(op1:Double,op2:Double)->Double{
        return op1*op2
    }</span>

좋은 웹페이지 즐겨찾기