Upvote:17

Aprove answer
func onButtonTap(...) {
    Task { @MainActor in
        ....
    }
}

Credit Goes to: stackoverflow.com

Related question with same questions but different answers