Member-only story
Adventures in Swift UI | Protocol Composition & Mixins to build complex User Interfaces
Composition over inheritance is how the story goes as far as design patterns are concerned.
We will review how we can use protocol composition and functional paradigm such as mixins to build a complex back end for Swift UI rendering.
Several Swift developers use protocols just as ‘interfaces’ in a traditional object-oriented programming sense. Say, relative to Java as an example.
Protocols are much more than interfaces, they are the way to implement object-oriented principles and design patterns in Swift.
What is a mixin, anyway?
A mixin is a 3 part recipe. 1 — composition of interfaces, 2 — Implementation of those interfaces called traits, and 3 — data structures associated with the container objects.
Let me refresh or re-define a couple of terms for you, so we are on the same page relative to the rest of the code.
Protocol Composition
In Swift, you can combine multiple protocols into a single composite protocol. So, the data types (class, struct, or enum) that are compliant need to implement…