Skip to content

Latest commit

 

History

History
83 lines (48 loc) · 1.84 KB

File metadata and controls

83 lines (48 loc) · 1.84 KB

Generics

Agenda

  • Define and use Generics
  • Identify Generics in the networking layer
  • Lab time

Generics

Generic code = flexible & reusable functions and types that can work with any type, based on defined requirements.

Generics are one of the most powrful features of Swift and a lot of the standard library is built with generic code.

We've been using generic code since long time ago, think about arrays. 🤔

@frozen struct Array<Element>

The Array type is generic – it doesn’t declare any specific data type.

array

Generics in action 😎

Replit demo

Exploring Generics

You can create your own generics. Follow this replit to learn how and then complete the challenges.

Start with the README.md file.

🧐 Reflection Question - 5 min

Why implement Generics when we already know about Inheritance?

Think about this question and when you are ready, share your answer in the chat.

Generics in the Networking Layer

Handling the Response

Making calls