SwiftUI ForEach with id fails at Runtime on Beta 6.1+

The following simplified code compiles but fails at runtime (crash!) "precondition failure: attribute failed to set an initial value: X" error.


Doing some tests, it seems that SwiftUI ForEach does not like the "id:\.self" as would be the common way of using a simple Array on ForEach?


I know that it is easy and convenient to comply the content of Array to identifiable but there are cases (such as using CaseIterable) where just using id:\.self would be the way to go:


@State var Value: Float = 0.0
private var baseChoices: [Float] = [436, 437, 438, 439, 440, 441, 442, 443, 444] // declared at the beginning of view Struct

/// inside the body:
HStack {
     Picker(selection: $Value,
          label: Text("watchos.tuner.base").bold().modifier(PickerLabel()) ) {
                    ForEach(baseChoices, id: \.self) { val in
                        Text("\(Int(val))").minimumScaleFactor(0.5)
                    }
                }
}


Note that this works totally fine on WatchOS 6 and any non-beta but systematically leading to Crash on all available betas as of today.


This seems to be the case with all uses of "id" on ForEach.

Accepted Reply

For info: This is now fixed in WatchOS 6.1 beta 4 - build 17S5076a (whose release note is empty BTW).

Replies

For info: This is now fixed in WatchOS 6.1 beta 4 - build 17S5076a (whose release note is empty BTW).