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

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

Top comments (0)