-
|
This is from the documentation:
Does this apply to a network request, or just a slow query? I want to show a spinner when a user sees my screen, because I am doing a network request to populate my database. After that, I want to show the list. Which scheduling option should I use in the case of a network request? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
The The publisher is subscribed when a view that contains a But when the database request is slow, this will block the main thread until the ValueObservation has performed its initial fetch. The user may see a noticeable delay before the view appears on screen, and the app won't be responsive. That's why "database requests that are too slow" should not use the
If your |
Beta Was this translation helpful? Give feedback.
The
scheduling: .immediateoption only applies to ValueObservation (documentation). It has the database observation publisher publish its first element immediately, right on subscription.The publisher is subscribed when a view that contains a
@Queryproperty enters the screen, when requested by SwiftUI, from the main thread. When this publisher is.immediate, this allows the view to display database value right from the start (with multiple benefits: see Why@Query?).But when the database request is slow, this will block the main thread until the ValueObservation has performed its initial fetch. The user may see a noticeable delay before the view appears on screen, and the app won't be …