April 2017
Intermediate to advanced
316 pages
9h 33m
English
In Chapter 3, Types and Type Casting we talked about Abstract versus Concrete types. Type erasure is a process to make abstract types such as Generics concrete.
Why we would want to do it? The answer is because we want to write code against contracts; in other words, we want to prefer composition over inheritance. Also, sometimes we would want to be more flexible with the types. This concept may sound complicated, so let's continue our example from the previous section to understand why and how we would create type-erased structures.
First, we want to examine if we can use CustomView type and create an array with CustomView elements. We will create a CustomView:
struct CustomDisabledButton: CustomView { typealias ViewType = ...Read now
Unlock full access