gpt4 book ai didi

swift - 不能对 '[...]' 类型的不可变值使用可变成员

转载 作者:行者123 更新时间:2023-11-28 11:27:34 26 4
gpt4 key购买 nike

我正在尝试转换一些过时的 swift 代码(不是我的)以构建 Swift 5。

这一行:

let nodeTypes = [smoothstepNodeType].sort({$0.name < $1.name})

出现错误:无法在类型为“[SweetcornNodeType]”的不可变值上使用可变成员

其他定义如下:

let smoothstepNodeType = SweetcornNodeType(name: "Smoothstep",
inputLabels: ["Edge 0: Red", "Edge 0: Green", "Edge 0: Blue", "Edge 1: Red", "Edge 1: Green", "Edge 1: Blue", "Value (x)", "Value (y)", "Value (z)"],
outputLabels: ["Red", "Green", "Blue"],
glslString: " vec3 $VAR_NAME = smoothstep(vec3($0, $1, $2), vec3($3, $4, $5), vec3($6, $7, $8)); \n")

struct SweetcornNodeType
{
init(name: String, inputLabels: [String], outputLabels: [String], glslString: String, includeFunction: String? = nil)
{
self.name = name
...
}


let name: String

}

想法?我没有看到变异成员在哪里。我删除了数组文字中的其他元素只是为了简化此处的显示。

最佳答案

以下应该有效。

 let nodeTypes = [smoothstepNodeType].sorted(by: {$0.name < $1.name})

希望这就是您所需要的。

关于swift - 不能对 '[...]' 类型的不可变值使用可变成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57742439/

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