Skip to main content

Command Palette

Search for a command to run...

SwiftUI + Concurrency Mock Interview

(Senior Level)

Published
4 min read
SwiftUI + Concurrency Mock Interview

Section 1 : Core Concept Warm-up

Question 1
Explain the SwiftUI view lifecycle. When is a view created, updated, and destroyed?

Follow-up:

  • Why is init rarely used for side effects in SwiftUI?

  • What causes a SwiftUI view to re-render?


Question 2
Explain the difference between .onAppear, .task, and Task {} in SwiftUI.

Follow-up:

  • Which one automatically cancels work when the view disappears?

  • What happens if a .task is restarted?


Question 3
What is the difference between @State, @StateObject, and @ObservedObject?

Follow-up:

  • What bug occurs if @ObservedObject is incorrectly used instead of @StateObject?

Section 2: Swift Concurrency Deep Dive

Question 4
Explain structured vs unstructured concurrency.

Follow-up:

  • Where does Task.detached fit?

  • Why is structured concurrency preferred?


Question 5
What are actors, and how do they guarantee thread safety?

Follow-up:

  • Can actors cause deadlocks?

  • When would you avoid using an actor?


Question 6
What happens when a Task is cancelled?

Follow-up:

  • How do you make your async functions cancellation-aware?

  • What happens to try await Task.sleep() on cancellation?


Section 3: Hands-on Coding (SwiftUI + Async)

Question 7
Write a SwiftUI view that fetches data when it appears and cancels the request if the user navigates away.

Expected focus:

  • .task

  • async/await

  • cancellation handling

Sample solution:

Copy

Copy

struct UserView: View {
    @State private var users: [String] = []

    var body: some View {
        List(users, id: \.self) { user in
            Text(user)
        }
        .task {
            await loadUsers()
        }
    }

    func loadUsers() async {
        do {
            try await Task.sleep(nanoseconds: 1_000_000_000)
            users = ["Alice", "Bob", "Charlie"]
        } catch {
            print("Task cancelled")
        }
    }
}

Question 8
How would you debounce a search query in SwiftUI using concurrency?

Expected discussion:

  • .task(id:)

  • cancellation

  • delay with Task.sleep


Section 4: State, Data Flow & Performance

Question 9
How does SwiftUI determine when to re-render a view?

Follow-up:

  • Why does updating a non-@State variable not trigger a UI update?

Question 10
You have a SwiftUI list with poor scrolling performance. How do you debug and fix it?

Expected discussion:

  • View identity

  • id

  • Avoiding heavy work in body

  • Lazy containers


Section 5: Architecture with SwiftUI & Concurrency

Question 11
How would you architect a SwiftUI app using MVVM with async/await?

Follow-up:

  • Where should network calls live?

  • Should ViewModels be @MainActor?


Question 12
Explain how dependency injection works in SwiftUI.

Follow-up:

  • Environment vs initializer injection

  • Testability concerns


Section 6: Error Handling & Resilience

Question 13
How do you handle errors in SwiftUI async flows?

Follow-up:

  • How do you surface errors to the UI?

  • How do you retry failed tasks?


Question 14
How do you implement offline support with SwiftUI and async APIs?

Expected discussion:

  • Caching

  • Persistence

  • Sync conflicts


Section 7: Advanced Concurrency Scenarios

Question 15
How do you limit the number of concurrent network requests?

Follow-up:

  • Task groups

  • Semaphores vs structured concurrency


Question 16
Explain withTaskGroup.

Follow-up:

  • When would you use it instead of async let?

Section 8: Debugging & Real-World Scenarios

Question 17
A SwiftUI screen randomly updates multiple times. How do you debug it?

Expected discussion:

  • State ownership

  • Multiple .task modifiers

  • View identity changes


Question 18
You notice memory leaks in a SwiftUI + async app. What do you check?

Expected discussion:

  • Retained tasks

  • Strong references in ViewModels

  • Instruments


Section 9: Decision-Making Questions

Question 19
When would you still prefer UIKit over SwiftUI?

Follow-up:

  • Performance

  • Custom gestures

  • Legacy codebases


Question 20
If Apple introduces a new concurrency feature tomorrow, how do you evaluate whether to adopt it?

Expected discussion:

  • Stability

  • Backward compatibility

  • Team readiness


Evaluation

Strong candidates should:

  • Explain trade-offs clearly

  • Understand lifecycle and cancellation deeply

  • Avoid memory and concurrency pitfalls

  • Design for testability and scale

  • Write clean, idiomatic SwiftUI code


About Me

Exploring iOS, Swift, and Kotlin through real-world challenges, clean architecture, and production-ready mobile solutions.

More from this blog

Dev on Mobile

12 posts

Practical mobile development with iOS, Swift, and Kotlin, focused on real-world examples, clean architecture, performance, and security.