Browse Questions
  • Both manage concurrent work, but async/await (introduced in Swift 5.5) is structured and compiler-checked, while GCD is unstructured and callback-based.
  • FlowLayout uses the Layout protocol (iOS 16+) — SwiftUI's official first-party layout system.
  • Snapshot testing captures a reference image of a view and compares future runs against it.
  • Identifiable requires a type to have a unique id property.

Answer: Identifiable requires a type to have a unique id property. SwiftUI uses this in ForEach and List to track which items are which across state changes — enabling correct animations and avoiding UI glitches.

Code Example:

struct Article: Identifiable {
    let id: UUID
    let title: String
}

// SwiftUI can now track each Article by id
List(articles) { article in
    Text(article.title)
}

// Without Identifiable — must provide keypath manually
List(articles, id: \.title) { article in
    Text(article.title)
}
// ⚠️ Only safe if titles are unique — id should always be truly unique

Key Points:

  • id can be any Hashable type — UUID, Int, String
  • Using a non-unique id causes incorrect animations and potential crashes
  • UUID() is the safest default for new models