Created
July 8, 2025 11:16
-
-
Save jacobsapps/b05c4559493d38705583eb172af5cff3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// All code runs on MainActor | |
@MainActor | |
func updateUI(with text: String) { | |
label.text = text | |
} | |
// properties and functions implicitly marked @MainActor | |
@MainActor | |
class ViewModel: ObservableObject { | |
// ... | |
} | |
// Use MainActor in async contexts | |
Task { @MainActor in | |
let data = await getData() // await can run off main actor | |
self.data = data // returns to main actor | |
} | |
// safely jump from async context to main actor | |
await MainActor.run { | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment