问题
TL:DR
There seems to be a chicken-and-egg paradox in this View initializer.
The Code
This happens often enough to me that I must be missing something fundamental about @State. Namely the compiler seems to be saying I can't set pickerIndex until pickerIndex has been set, and I can't exit the initializer without setting pickerIndex.
(The LetterSelection variable tracks a letter of the alphabet, but I don't think its details are relevant.)
回答1:
Note: it is better to provide code "as code", so it could be easier edited
In the described case it needs to initialize not property value but the state wrapper itself, like
self._pickerIndex = State(initialValue: sel.current.idx)
来源:https://stackoverflow.com/questions/61650040/swiftui-initializer-apparent-circularity