你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> IOS_swift_函數用法

IOS_swift_函數用法

編輯:IOS開發綜合

1.多個返回值

 

 

    func x(x:Int, y:Int)->(Int, Int){
        let a = x+y
        let b = x-y
        return (a, b)
    }
    let (a, b) = x(10, y: 3)
    print(a = (a))
    let val = x(10, y: 3)
    print(val = (val.0))

 

 

2.默認參數

 

 

    func x(x:Int, y:Int=10)->(Int, Int){
        let a = x+y
        let b = x-y
        return (a, b)
    }
    x(10)
    x(10, y: 3)

 

 

3.函數參數

 

 

    z(y, x: 10, y: 7)
    
    func x(x:Int, y:Int)->(Int, Int){
        let a = x+y
        let b = x-y
        return (a, b)
    }
    
    func z(fx:(Int, Int)->(Int,Int), x:Int, y:Int){
        let x = fx(x, y).0;
        print(x = (x))
    }

 

 

4.關鍵字inout

 

 

    func change(inout m:Int){
        m = 10;
    }
    var xx = 2;
    change(&xx)
    print(xx = (xx))


 

 

 

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved