Browse Questions
  • Inside a ScrollView, SwiftUI's vertical scroll direction makes height unconstrained.
  • SPM is Apple's built-in dependency manager for Swift.
  • Declare a var with a get block that returns the value and a set block that updates the underlying stored state.
  • Both manage concurrent work, but async/await (introduced in Swift 5.5) is structured and compiler-checked, while GCD is unstructured and callback-based.

Answer: Both manage concurrent work, but async/await (introduced in Swift 5.5) is structured and compiler-checked, while GCD is unstructured and callback-based.

async/awaitGCD
StyleStructuredUnstructured
ReadabilityLinear codeNested callbacks
Error handlingthrows / tryManual
CancellationAutomatic (Tasks)Manual
Thread safetyEnforced by actorsManual

Code Example:

// ❌ GCD — nested, harder to read and reason about
func loadUser(completion: @escaping (User?) -> Void) {
    DispatchQueue.global().async {
        let user = fetchFromNetwork()
        DispatchQueue.main.async {
            completion(user)
        }
    }
}

// ✅ async/await — reads like synchronous code
func loadUser() async throws -> User {
    let user = try await fetchFromNetwork()
    return user
}