Swift:在“:"之前有两个变量的原因 [英] Swift: reason for two variables before ":"

查看:79
本文介绍了Swift:在“:"之前有两个变量的原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是Apple的官方Doc示例:

Here's Apple's official Doc example:

class Counter {
    var count: Int = 0
    func incrementBy(amount:Int, numberOfTimes times:Int){
        count += amount * times
    }
}

var counter = Counter()
counter.incrementBy(2, numberOfTimes: 8)

实际上,以下代码有什么区别:

Actually, what's the difference with the following codes:

class Counter {
    var count: Int = 0
    func incrementBy(amount:Int, numberOfTimes:Int){
        count += amount * numberOfTimes
    }
}

var counter = Counter()
counter.incrementBy(2, numberOfTimes: 8)

为什么将times放在正式文档中? 我是编程新手,有人可以解释其背后的理论吗? 谢谢!

why times is put inside in the official Doc? i'm new to programming, can someone explain the theory behind? Thx!!

推荐答案

numberOfTimes是外部参数名称/标签,而times是内部参数名称,仅在函数内部使用.参见

numberOfTimes is the external parameter name/label, whereas times is the internal parameter name, used only inside the function. See Function Parameter Names for more information.

这篇关于Swift:在“:"之前有两个变量的原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆