只需使用a
[String]
:
@State var indicators = ["pending", "pending", "pending", "pending"]
这使得更新数组变得容易:
indicators[3] = "completed"
仅将数组转换为
[StepperIndicationType<MyView>]
在最后一刻。
StepperView()
// ...
.indicators(indicators.map { .custom(MyView(name: $0)) })
// ...
或者,您可以添加
name
财产
StepperIndicationType
在扩展中,尽管我觉得这很丑陋。
extension StepperIndicationType<MyView> {
var name: String? {
get {
if case let .custom(content) = self {
content.name
} else {
nil
}
}
set {
if case var .custom(content) = self, let newValue {
content.name = newValue
self = .custom(content)
}
}
}
}
那么
indicators[3].name = "completed"
将编译。