Suggested approach: Generics allow us to create types and functions that can be adapted to use different kinds of data for extra flexibility and safety.
Generics are most commonly used to add type safety to collections – even if you don't create them yourself much, you certainly use them because [String]
is really Array<String>
under the hood.
For bonus points, talk about how protocols use associated types rather than generics to achieve a similar result.
Estimated difficulty: Intermediate
Watch me answer this question in detail
See the full list of iOS interview questions
Link copied to your pasteboard.