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

Caio Zullo
Essential Developer — iOS
2 min readSep 25, 2018
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.

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

--

--

Caio Zullo
Essential Developer — iOS

I love building robust, well-engineered, and beautiful iOS applications and coaching developers to achieve their best potential @ https://essentialdeveloper.com