Michael Long
Jan 26, 2023

--

Agree. Add a CountryViewModeling protocol that any "country" type can conform to that returns the flag, name, and description.

Or instead have the protocol simply be something like ImageDetailing that defines a var that returns a name/image/description struct for consumption by the VM.

let details = (country as? ImageDetailing)?.details

And which avoids the "registration" step. That might still be needed if you need to iterate over the list... then again, we're back to having a single spot that must change whenever a new type is defined.

Understand the example, but it doesn't sell the technique and as such seems a very boilerplate heavy solution to the problem.

--

--

Michael Long
Michael Long

Written by Michael Long

I write about Apple, Swift, and SwiftUI in particular, and technology in general. I'm also a Lead iOS Engineer at InRhythm, a modern digital consulting firm.

No responses yet