美文网首页
16.swift-func函数嵌套

16.swift-func函数嵌套

作者: ChaosHeart | 来源:发表于2021-07-21 16:05 被阅读0次

    //: Playground - noun: a place where people can play

    import UIKit
    
    
    
    //注意:
    /*
     1.内部参数:形参
     2.外部参数:实参
     */
    //行参
    func sum(one:Int,two:Int)->Int{
        return one + two;
    }
    //实参
    sum(one: 1, two: 2);
    
    
    
    /*
     默认参数
     */
    func makeCoffee(coffee:String = "雀巢")->String{
        return "制作一杯\(coffee)咖啡";
    }
    makeCoffee(coffee: "拿铁");
    makeCoffee();
    
    /*
     Int : 可变参数的个数
     */
    func summ(nums : Int...)->Int{
        var total: Int = 0;
        for number in nums {
            total += number;
        }
        return total / Int(nums.count)
    }
    summ(nums: 10,9,8,7,6,5);
    
    /*
     Double : 可变参数的个数
     */
    func arithmeticMean(numbers: Double...) -> Double {
        var total: Double = 0
        for number in numbers {
            total += number
        }
        return total / Double(numbers.count)
    }
    arithmeticMean(numbers: 10.0000,9.00,8.00,7.00,6.00,5.00);
    
    /*
     指针类型
     */
    var m = 20;
    var n = 30;
    func swapNum( m:inout Int, n:inout Int) {
        var n = n;
        var m = m;
        let tmp = m;
        m = n;
        n = tmp;
    }
    swapNum(m: &m, n: &n);
    print("m:\(m)");
    print("n:\(n)");
    
    
    /*1.函数嵌套*/
    test();
    /// 测试
    func test(){
        func demo(){
            print("demo");
        }
        print("test");
        demo();
    }
    
    
    
    /// 2.函数嵌套
    func testDemo() {
        test111();
    }
    /// 测试
    func test111() {
        print("testDemo")
    }
    testDemo();
    
    
    

    相关文章

      网友评论

          本文标题:16.swift-func函数嵌套

          本文链接:https://www.haomeiwen.com/subject/fdrzlltx.html