I tried:
Clean project
Clean derived data
Resolve Package Versions (File > Package)
Update to Latest Package Versions (File > Package)
Restarted Xcode
Restarted Mac
And restarting the Mac is what worked 🥲
Post
Replies
Boosts
Views
Activity
You can use LazyView (by Chris Eidhof): https://gist.github.com/chriseidhof/d2fcafb53843df343fe07f3c0dac41d5
Luca Bernardi, a SwiftUI engineer, said in a Twitter thread this is how SwiftUI works:
Exactly, SwiftUI expects view creation to be cheap: the system can recreate views often.
For example, allocating NSFormatter in the init is not a good: you’ll pay the cost of heap allocation (and initialization) every time the view hierarchy is updated.
(I can't link the referenced tweet here but the reference id of the tweet is 1144312093597769728.) That said, I'd like to understand why it works like this for NavigationLink but not for views presented modally, and why not give us, the developers, the option built-in in SwiftUI, so we are left to choose the approach that fits best for us.
You can use LazyView (by Chris Eidhof): https://gist.github.com/chriseidhof/d2fcafb53843df343fe07f3c0dac41d5
Luca Bernardi, a SwiftUI engineer, said in a Twitter thread this is how SwiftUI works:
Exactly, SwiftUI expects view creation to be cheap: the system can recreate views often.
For example, allocating NSFormatter in the init is not a good: you’ll pay the cost of heap allocation (and initialization) every time the view hierarchy is updated.
(I can't link the referenced tweet here but the reference id of the tweet is 1144312093597769728.) That said, I'd like to understand why it works like this for NavigationLink but not for views presented modally, and why not give us, the developers, the option built-in in SwiftUI, so we are left to choose the approach that fits best for us.
It looks like you show a deeplink example in Fruta app (https://developer.apple.com/documentation/swiftui/fruta_building_a_feature-rich_app_with_swiftui, check out onContinueUserActivity in FrutaApp.swift).
Although it's good that I finally see an example from Apple, I think the community will benefit if it is covered in an article or documentation piece.
Thank you for your answer, Documentation Engineer.
I have another question to follow: How do you mock @StateObject properties for testing purposes then?