Swift gurus are these two equivalent?

Trying to get a ScrollView to jump back to the previous first item when new items are added and even in a test project this seems to be required before it works reliably!

This itself is in an .onChange modifier listening to the items if that helps with context

#swift #iOSdev

@jknlsn scrollTo isn't labeled as MainActor/Sendable, so I’d be wary of calling it from inside a Task.

It's likely your onChange is being fired before the view has had a chance to redraw, so there's nothing to scroll to yet.

@phill ah, thanks!

Any ideas on ways to prevent this until the view is redrawn? Or just .asyncAfter and hope for the best haha 🤔

Follow

@jknlsn You could try .task(id: currentFirst) { //do scroll from main actor }, otherwise… mastodon.notsobig.co/@phill/11

Sign in to participate in the conversation
The Not So Big Company

The home of The Not So Big Company on Mastodon.