Bird
0
0

How do you correctly declare an asynchronous function that must execute on the main actor in Swift?

easy📝 Syntax Q3 of 15
iOS Swift - Concurrency
How do you correctly declare an asynchronous function that must execute on the main actor in Swift?
Afunc @MainActor updateUI() async { /* code */ }
B@MainActor func updateUI() async { /* code */ }
Cfunc updateUI() async @MainActor { /* code */ }
D@MainActor async func updateUI() { /* code */ }
Step-by-Step Solution
Solution:
  1. Step 1: Attribute Placement

    @MainActor is placed before the function declaration.
  2. Step 2: Async Keyword

    Async comes after the function name and before the braces.
  3. Final Answer:

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

    @MainActor precedes func, async follows func name [OK]
Quick Trick: @MainActor precedes func, async follows func name [OK]
Common Mistakes:
  • Placing @MainActor after func keyword
  • Putting async before @MainActor
  • Misordering async and @MainActor keywords

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes