gpt4 book ai didi

swift - 如何修复 'can not use mutating member on immutable value' ?

转载 作者:搜寻专家 更新时间:2023-10-30 22:03:38 24 4
gpt4 key购买 nike

<分区>

获取错误:

Error : cannot use mutating member on immutable value : 'fromArray' is a 'let' constant

在下面的代码中:

func removing (item: Int, fromArray: [Int]) -> [Int] {

for i in 0...fromArray.count-1 {
if fromArray[i] == item {
let index = i
fromArray.remove(at: index) // <-- error is here
}
}
return fromArray
}

var anarray : [Int] = [1, 2,3, 4 ,3]
var x = 3
removing(item: x, fromArray: anarray)

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