0
0
iOS Swiftmobile~5 mins

Identifiable protocol in iOS Swift - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the Identifiable protocol in Swift?
The Identifiable protocol helps uniquely identify instances of a type using an id property. This is useful for lists and UI updates where each item needs a stable identity.
Click to reveal answer
beginner
Which property must a type conforming to Identifiable provide?
A type conforming to Identifiable must provide a property called id that uniquely identifies the instance. The type of id is usually UUID or another unique value type.
Click to reveal answer
intermediate
How does SwiftUI use the Identifiable protocol?
SwiftUI uses Identifiable to track and differentiate views in lists or collections. It helps SwiftUI know which views changed, moved, or were removed to update the UI efficiently.
Click to reveal answer
intermediate
Can the id property be any type in Identifiable?
Yes, the id property can be any type that conforms to Hashable. Common choices are UUID, Int, or String.
Click to reveal answer
beginner
Example: How to make a struct Person conform to Identifiable?
struct Person: Identifiable { var id = UUID() var name: String } This gives each Person a unique id automatically.
Click to reveal answer
What does the Identifiable protocol require?
AAn <code>id</code> property that uniquely identifies the instance
BA method called <code>identify()</code>
CA static property called <code>id</code>
DNo requirements, it's a marker protocol
Which type is commonly used for the id property in Identifiable?
AString
BDouble
CBool
DUUID
Why is Identifiable important in SwiftUI lists?
ATo style the list items
BTo sort the list alphabetically
CTo uniquely track each item for efficient UI updates
DTo add animations automatically
Can the id property be a custom type?
ANo, it must be UUID
BYes, if it conforms to Hashable
CNo, it must be Int
DYes, but only String or Int
What happens if two instances have the same id in an Identifiable collection?
ASwiftUI treats them as the same item
BSwiftUI crashes
CThey are treated as different items
DThe app ignores the <code>id</code> property
Explain how the Identifiable protocol helps SwiftUI manage lists.
Think about how SwiftUI knows which item changed in a list.
You got /4 concepts.
    Describe how to make a custom struct conform to Identifiable and why you would do it.
    Focus on the required property and its purpose.
    You got /4 concepts.