79426035

Date: 2025-02-10 03:35:12
Score: 1
Natty:
Report link

View functions by default now run on @MainActor. That means that by default your function looks like this @MainActor func saveIdsWatchedTime(). It doesn't matter if you call it from a Task since the function is has a @MainActor signature it will block the UI. You can move the Task inside the function instead of calling it inside onScrollVisibilityChange. Any assignment you make to a @State variable will still be made in the main actor therefore blocking the UI. Ideally you want to leave any assignments until the end of the function. Progress flags are usually an exception. The other solution is to declare saveIdsWatchedTime inside an @Observable object and mark the function as nonisolated and async. Note that in this case you'd have to move any @State variables to the @Observable object and make sure any UI exposed variables are called on the main actor since the function is now nonisolated.

Reasons:
  • Whitelisted phrase (-1): solution is
  • Long answer (-0.5):
  • No code block (0.5):
  • User mentioned (1): @MainActor
  • User mentioned (0): @MainActor
  • User mentioned (0): @MainActor
  • User mentioned (0): @State
  • User mentioned (0): @Observable
  • User mentioned (0): @State
  • User mentioned (0): @Observable
  • Single line (0.5):
  • Low reputation (0.5):
Posted by: Axel Rivera