Type Conversion & Generics in Swift

Where do generics fit in the big picture

Mark Lucking
Geek Culture

--

In the sixties, there were four major computer languages that ruled above all others. ALGOL, COBOL, FORTRAN, and LISP. With FORTRAN and ALGOL leading the way with typecasting. Although I think it was the son of ALGOL, PASCAL that took the most definitive steps as the decades past and ALGOL stepped aside. PASCAL was the language used to develop MacOS back then, and one that I suspect heavily influenced OBJECTIVE C design as well SWIFT.

Unsurprisingly perhaps, types haven’t changed that much in the last seventy years in fact. Which makes perfect sense since these concepts go back thousands of years. Indeed you can reasonably argue that it is encoded into the genome of mathematics itself.

All of which is why perhaps we’re all a bit lost on generics in Swift. You see for my money Apple has been trying to do some gene editing here with new abstract protocols called quite appropriately generics. But enough said let move off the theory and onto the practical.

The brief. Your client comes from the world of assemblers and wants to be able to cast all these types they have in Swift to each other. Sadly on this occasion, you the poor programmer are not being paid per line of code. No, your task is to do the job in no more than a dozen lines or less if…

--

--

Mark Lucking
Geek Culture

Coding for 35+ years, enjoying using and learning Swift/iOS development. Writer @ Better Programming, @The StartUp, @Mac O’Clock, Level Up Coding & More