tezvyn:

What is @MainActor and why does it matter?

Source: interviewintermediate

WHAT IT TESTS: thread safety for UI updates. OUTLINE: @MainActor is a global actor guaranteeing code runs on the main thread; annotate UI-updating types or methods so post-network state changes are main-thread safe.

WHAT IT TESTS: whether you understand the main-thread requirement for UI and how @MainActor enforces it at compile time. ANSWER OUTLINE: @MainActor is a global actor that serializes its work onto the main thread; you apply it to a view model, method, or property so the compiler guarantees those updates run on main; after an awaited network call resumes on a background executor, hopping back to a @MainActor context safely updates published state and UIKit views.

Read the original → interview

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

What is @MainActor and why does it matter? · Tezvyn