Member-only story

Adventures in Swift UI | Protocol Composition & Mixins to build complex User Interfaces

Suresh Kandula
8 min readFeb 26, 2024

--

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.

Photo by rocknwool on Unsplash

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…

--

--

Suresh Kandula
Suresh Kandula

Written by Suresh Kandula

#FinancialServices #Automotive #Architecture #LoveOfCoding

No responses yet