在Swift中我们可以在函数中改变函数的局部参数值吗?
喜欢:
func exampleFunction(value: String, index: Int) -> Bool {
value = "Changed Value" // Error
index = 3 // Error
return true
}
Run Code Online (Sandbox Code Playgroud)
在viewDidLoad()中调用函数:
var flag = exampleFunction("Passed Value", 2)
Run Code Online (Sandbox Code Playgroud)
这是否可以在exampleFunction范围中更改值和索引?如果不是有任何其他方式这样做?因为使用这个我们只改变temp的值.
var temp = value
temp = "temp Change"
Run Code Online (Sandbox Code Playgroud) 如何在没有RepeatedValues的情况下初始化具有最大容量的阵列?
var anotherThreeDoubles = Array(count: 3, repeatedValue: 2.5)
Run Code Online (Sandbox Code Playgroud)
就像在这个例子中使用repeatedValue一样.我们可以初始化没有价值吗?
swift ×2