本文主要是介绍Non-constant range: argument must be an integer literal,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
更新 Xcode IDE 后 ForEach 方法抛出了如下异常
Non-constant range: argument must be an integer literal
新增了指向性 id 参数 init(_:content:)
原始方法
ForEach(0 ..< pickerTitleColors.count) {Text(self.pickerTitleColors[$0]).tag($0).foregroundColor(self.pickerStyleColors[$0])
}
改进后
// 方式一
ForEach(0 ..< pickerTitleColors.count, id:\.self) {Text(self.pickerTitleColors[$0]).tag($0).foregroundColor(self.pickerStyleColors[$0])
}// 方式二
ForEach(0 ..< pickerTitleColors.count, id:\.self) { item inText(self.pickerTitleColors[item]).tag(item).foregroundColor(self.pickerStyleColors[item])
}// 方式三
ForEach(pickerTitleColors.indices, id:\.self) { item inText(self.pickerTitleColors[item]).tag(item).foregroundColor(self.pickerStyleColors[item])
}
以上便是此次分享的全部内容,希望能对大家有所帮助!
这篇关于Non-constant range: argument must be an integer literal的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!