Member-only story
Type Erasure in Swift
Get rid of that type information
Difficulty: Beginner | Easy | Normal | Challenging
This article has been developed using Xcode 11.4.1, and Swift 5.2.2
This article is example laden, and shows how I’ve used Type Erasure
in my production Apps. It should help if you wish to know what Type Erasure
is and how you might apply it in your Swift code.
Prerequisites:
- You will be expected to be aware how to make a Single View Application, or a Playground to run Swift code
- You will need to know about protocols in Swift
- The heart of this article is a constant (and annoying) talk about generics
Terminology:
Type Erasure: Removing type information
When programming in Swift we have a type-safe language, that is Swift is strongly typed.
Now sometimes you might want to use type erasure, that is removing type information to find out why you might want to lose information in this way we have to think about protocol-oriented programming and specific implementations of the same…