SwiftUI does not update the UI as expected

Following code updates the values in the "numbers" array properly when I touch the "increment" button (I see the updated value when I go back), but the display on the leaf page (Text inside NavigationLink) does not update immediately for some reason (if I go back and navigate back to the leaf page again, it displays the updated value).

I'd appreciate if somebody could tell me why it does not update correctly.


Code Block swift
import SwiftUI
struct NumberHolder: Identifiable {
let id = UUID()
let value:Int
}
struct Playground: View {
@State var numbers:[NumberHolder] = [
NumberHolder(value:1),
NumberHolder(value:2),
NumberHolder(value:3),
NumberHolder(value:4),
]
var body: some View {
NavigationView {
List(numbers.indices) { index in
let number = numbers[index]
NavigationLink(destination: VStack {
Text("Number \(number.value)")
Button("Increment") {
numbers[index] = NumberHolder(value: number.value + 1)
}
} ) {
Text("Number \(number.value)")
}
}
}
}
}
struct Playground_Previews: PreviewProvider {
static var previews: some View {
Playground()
}
}


Replies

I am not having this problem.
When running this, tapping the increment button increments the number on the detail view and also in the list row at the same time straight away without any delay.
Thank you for running this code on your machine, BabyJ. This helps a lot!
After further testing, I found out that this problem happens only under Xcode 12.2 beta 2, not on Xcode 12.0.
This seems like a bug on Xcode 12.2 beta 2.
Same issue here. I think it's a bug (or a new intended behavior) that comes with iOS 14. Using Xcode 12.2 but running on iOS 13 works properly.