Bird
0
0

What is the main purpose of using @MainActor in Swift UI code?

easy📝 Conceptual Q11 of 15
iOS Swift - Concurrency
What is the main purpose of using @MainActor in Swift UI code?
ATo ensure UI updates happen on the main thread
BTo run background tasks faster
CTo prevent memory leaks
DTo encrypt user data
Step-by-Step Solution
Solution:
  1. Step 1: Understand UI thread requirements

    UI updates must happen on the main thread to avoid crashes and keep the app smooth.
  2. Step 2: Role of @MainActor

    @MainActor ensures the annotated code runs on the main thread, making UI updates safe.
  3. Final Answer:

    To ensure UI updates happen on the main thread -> Option A
  4. Quick Check:

    MainActor = UI updates on main thread [OK]
Quick Trick: MainActor always means UI code runs on main thread [OK]
Common Mistakes:
  • Thinking @MainActor speeds up background tasks
  • Confusing @MainActor with memory management
  • Assuming @MainActor encrypts data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes