|
With the update to Xcdoe 13.4 previous projects that used the following code:
Now throws the warning: Non-constant range: argument must be an integer literal It can be fixed by adding
Can anyone throw some light on why |
|
It's always been that way. When you use a range in a So instead of using this initializer:
you should use this initializer:
which is "Available when There was previously no warning about this so you would just crash unexpectedly if you were unaware of the above, but I guess Xcode 13.4 now supplies a warning to make you aware of the issue. |
|
This warning also comes up in the Cupcake Corner project in ContentViews ForEach when looping over the Order.types.indices. Adding the id: .self clears the error, but it did not seem to be an issue in Pauls code. |
|
Seeing this issue with Challenge 1: Converter, Advanced project about 34 minutes in for Picker("Conversion", selection: $selectedUnits) { ForEach(0..<conversions.count) { Text(conversions[$0]) } } |
|
Same as tomtubbs. The following throws the warning:
So I have to use a defined count instead:
Using |
|
You can use this instead:
But is
Basically, you should always try to use that kind of |
|
So awesome. Your first solution worked perfectly, @roosterboy. Thank you very much, friend. 🙌🏻 |
|
@roosterboy using the alternative initialiser with the
|
|
Because what I said is true.
This
That's because the range is read in once when the (You'll also get a warning in the debugger telling you that the current But this form of
Because SwiftUI creates Here's an example to prove it:
You can comment/uncomment each of the |
SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!
Sponsor Hacking with Swift and reach the world's largest Swift community!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.