DEV Community

Cover image for Migrating to Swift 4.2 using a TDD + Git workflow [S01 Extras]
⛩ Caio Zullo for ⛩ Essential Developer

Posted on • Originally published at essentialdeveloper.com on

3 2

Migrating to Swift 4.2 using a TDD + Git workflow [S01 Extras]

Watch on YouTube

In this episode, we migrate the Quiz project and its dependencies to Swift 4.2 and modernize our code with the newest additions.

Just like in the Swift 4 and Swift 4.1 migration episodes, we migrate each module independently, while making sure that all tests are passing at every step and that we end up with no build warnings.

One delightful change that Swift 4.2 brings is the improved ability of the compiler to synthesize an implementation of the Hashable protocol. We take advantage of this change and, by following our standard workflow combining Git and Automated Tests, we remove our custom implementation of hashValue we wrote for the Question type in Episode 13 - Improving the Game Flow with Swift Generics.

During the Hashable refactoring, we are surprised by some of the tests breaking. We resist the urge of deleting the tests by following a highly disciplined approach to solving the problem.

It’s important to notice that without a test suite we trust, it can be much harder to do such changes with confidence.

Finally, we take advantage of the new Sequence.shuffled function that Swift 4.2 offers. We use Sequence.shuffled to showcase how to test randomness by using probability rather than mocking. By not relying on mocking, we can freely change the implementation of our code without breaking any of the tests.

Subscribe now to our Youtube channel and catch free new episodes every week.


Originally published at www.essentialdeveloper.com.

We’ve been helping dedicated developers to get from low paying jobs to high tier roles – sometimes in a matter of weeks! To do so, we continuously run and share free market researches on how to improve your skills with Empathy, Integrity, and Economics in mind. If you want to step up in your career, access now our latest research for free.

Let’s connect

If you enjoyed this article, visit us at https://essentialdeveloper.com and get more in-depth tailored content like this.

Follow us on: YouTubeTwitterFacebookGitHub

ACI image

ACI.dev: The Only MCP Server Your AI Agents Need

ACI.dev’s open-source tool-use platform and Unified MCP Server turns 600+ functions into two simple MCP tools on one server—search and execute. Comes with multi-tenant auth and natural-language permission scopes. 100% open-source under Apache 2.0.

Star our GitHub!

Top comments (0)

AI Agent image

How to Build an AI Agent with Semantic Kernel (and More!)

Join Developer Advocate Luce Carter for a hands-on tutorial on building an AI-powered dinner recommendation agent. Discover how to integrate Microsoft Semantic Kernel, MongoDB Atlas, C#, and OpenAI for ingredient checks and smart restaurant suggestions.

Watch the video 📺

👋 Kindness is contagious

Dive into this thoughtful article, cherished within the supportive DEV Community. Coders of every background are encouraged to share and grow our collective expertise.

A genuine "thank you" can brighten someone’s day—drop your appreciation in the comments below!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found value here? A quick thank you to the author makes a big difference.

Okay