Bird
0
0

Which of the following is the correct way to declare a function that updates UI using MainActor in Swift?

easy📝 Syntax Q12 of 15
iOS Swift - Concurrency
Which of the following is the correct way to declare a function that updates UI using MainActor in Swift?
Afunc updateUI() { @MainActor /* code */ }
Bfunc updateUI() @MainActor { /* code */ }
Cfunc @MainActor updateUI() { /* code */ }
D@MainActor func updateUI() { /* code */ }
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct syntax for @MainActor

    @MainActor is an attribute placed before the function declaration.
  2. Step 2: Check each option

    @MainActor func updateUI() { /* code */ } correctly places @MainActor before the function name.
  3. Final Answer:

    @MainActor func updateUI() { /* code */ } -> Option D
  4. Quick Check:

    @MainActor before func = correct syntax [OK]
Quick Trick: @MainActor goes before func keyword [OK]
Common Mistakes:
  • Placing @MainActor after func name
  • Putting @MainActor inside function body
  • Using @MainActor as a suffix

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes