Hey Quinn, @DTS Engineer
My bad—initially, I wrote the entire code in the view controller to simplify things (yes, I know, Massive View Controller is not a great practice! LOL). I’ve now restructured the code using a simple VIPER architecture.
The Actual Goal:
I want to fetch data from a server off the main thread, including any data conversion needed for the UI, and then update the UI before and after the fetch.
How I Structured It:
• The dataTask is triggered inside the interactor’s async fetchListData() function.
• In the presenter (which is a class, not an actor), I call fetchListData() using Task. However, since Task doesn’t inherit an actor context, after an await suspension point, it might resume on a different thread. To handle this, I annotated my presenter method with @MainActor to ensure UI updates happen on the main thread.
My Questions:
Is using @MainActor in the Task the best practice? Or should I make my entire presenter a MainActor?
If I use @MainActor in the presenter, will the interactor’s fetchListData() always be executed off the main thread? I don’t want to overload the main thread with network calls or data conversion.
Is there a way to ensure that the interactor always returns values on the main thread so that I don’t need to rely on @MainActor annotations in the presenter?
Git repo : https://github.com/praveeniroh/AsynAwaitTest
Post
Replies
Boosts
Views
Activity
@DTS Engineer My goal isn't just about fetching an image; it's about hitting any API. In the traditional closure-based flow, we manually switch to a background thread to make the API call and then switch back to the main thread to handle the result. I want to achieve the same functionality using structured concurrency,
@Frameworks Engineer tabBarController:sidebar:updateItem: function is called in a random order after selecting a tab, how can I properly update the tint color for the selected item?(while hardware keyboard is connected and focus changed)
@DTS Engineer Any workaround for this issue
@Frameworks Engineer The provided tint color is not applied to images in UITab, unlike in UITabBarItem. How can this be handled?
And is there any workaround to update sidebar's accent color to use tintColor?
@Frameworks Engineer I was able to update the tint color as you mentioned. However, the tint often doesn't update for the selected tab item. This issue seems to persist even in native apps.
Did you add common app group between your main target and background asset target? Kindly check app common group exist in Targets -> -> Signing & Capabilities and Targets -> <AppName (main Target)> -> Signing & Capabilities
I tried to observe the Stale state , but for stale state,I got call back only when I opened the app by tapping live activity. Otherwise the stale state change is not observed by activityStateUpdates even after the stale date
Thanks for the update, My bad. Instead of domain name ,I provided domain name with scheme (https://w0.peakpx.com)