iOS开发程序员

巩固—Swift 5.0 基础知识(二)

2017-10-12  本文已影响0人  永断阎罗

函数

定义:函数是执行特定任务的自包含代码块。(Swift中每个函数都有一个类型,由函数的参数类型和返回类型组成)。
使用:

    func arithmeticMean(_ numbers: Double...) -> Double {
        var total: Double = 0
        for number in numbers {
            total += number
        }
        return total / Double(numbers.count)
    }
    arithmeticMean(1, 2, 3, 4, 5)
    // returns 3.0, which is the arithmetic mean of these five numbers
    arithmeticMean(3, 8.25, 18.75)
    // returns 10.0, which is the arithmetic mean of these three numbers

闭包

枚举

类和结构体

属性

方法

上一篇 下一篇

猜你喜欢

热点阅读