Firstly I would like to say thank you for the excellent iDine sample project! Superb! I've implemented it using Xcode 11.4 beta 3 and whilst doing so, learned heaps about SwiftUI.
However, when I run the project and select a tip amount on the CheckoutView
view, I get a Xcode warning message in the console which really bugs me. (This warning also popped up when I clicked the "Confirm Order' button.) The warning does not affect the functionality of the app, but as I'm sure you can appreciate, that's not really the point.
Whenever I click a tip amount, using the Picker
with the SegmentedPickerStyle()
, Xcode produces the following warning:
ForEach<Range<Int>, Int, Text> count (3) != its initial count (1). `ForEach(_:content:)` should only be used for *constant* data. Instead conform data to `Identifiable` or use `ForEach(_:id:content:)` and provide an explicit `id`!
I've searched google (StackOverflow), tried a bunch of things using different ForEach
initialisers, changed/replaced static let tipamounts = [ ... ]
with various other data types, including an array of Identifiable
struct that contains let id: Int; let amount: Int
..., but nothing has helped. The warning continues to be printed each time I click a tip amount. *(What is interesting though is that when I go to the CheckoutView
from the OrderView
using the Place Order
navlink, the view is always rendered without the warning, though the default @State var tipAmount = 1
(i.e. is not 0).
With all the things I've tried and Xcode's weird error messages when views aren't quite right, I'm almost of the opinion that the problem may be somewhere else in the view but don't know where. (With respect to this question, my implementation of CheckoutView
is as per the tutorial.)
Does anyone know how to resolve this issue?
PS.. I have extended the project to use MVVM instead of MV and used @ObservedObject instead of @EnvitormentObject throughout.