gpt4 book ai didi

ios - didMove之间有什么区别(查看: SKView) and didMoveToView(view: SKView)?

转载 作者:可可西里 更新时间:2023-10-31 23:56:53 26 4
gpt4 key购买 nike

如题所示,didMove(to view: SKView) 和 didMoveToView(view: SKView) 有什么区别?

我知道 didMoveToView 是方法,并且该 View 在旧(?)版本中属于 SKView 类型。我不明白将“查看:SKView”传递给 didMove 方法的处理。 “to”和“view”是分开的变量吗? “to”是“didMove”的一部分吗?这是怎么回事?

编辑:我知道他们都完成了同样的事情 - 但为什么“to”在参数通常所在的区域?这有什么好处吗?这似乎是不必要的并发症?

最佳答案

区别仅在于语法。

新的 Swift 3 语法是 didMove(to view: SKView)

在 Swift 中:

Each function parameter has both an argument label and a parameter name.The argument label is used when calling the function; each argument is written in the function call with its argument label before it. The parameter name is used in the implementation of the function. By default, parameters use their parameter name as their argument label.

func someFunction(argumentLabel parameterName: Int) {
// In the function body, parameterName refers to the argument value
// for that parameter.
}

所以,swift 3版本中的to只是参数标签


可能你也见过不需要插入参数名的函数。

如果您不需要参数的参数标签,请为该参数写一个下划线 (_) 而不是显式参数标签。

func someFunction(_ firstParameterName: Int, secondParameterName: Int) {
// In the function body, firstParameterName and secondParameterName
// refer to the argument values for the first and second parameters.
}
someFunction(1, secondParameterName: 2)

希望它有助于更​​好地理解这些修改:您可以找到更多详细信息 here

关于ios - didMove之间有什么区别(查看: SKView) and didMoveToView(view: SKView)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40580873/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com