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

Опубликовано: 25 Сентябрь 2018
на канале: Essential Developer
2,841
61

★ Register Now to Our Free iOS Career Course! https://www.essentialdeveloper.com/co...

Subscribe to our channel: https://www.youtube.com/essentialdeve...

Source code: https://github.com/essentialdeveloper...

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 (https://www.essentialdeveloper.com/ar...) and Swift 4.1 (https://www.essentialdeveloper.com/ar...) 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 (https://www.essentialdeveloper.com/ar....

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.

★ Professional iOS Engineering S01

Take your skillset to the next level and boost your career https://www.essentialdeveloper.com/pr...

★ Download our new app

You can download Neat Trivia from the App Store today at https://itunes.apple.com/app/id125311....

Connect with us on:

• Website: https://www.essentialdeveloper.com
• Twitter:   / essentialdevcom  
• Facebook:   / essentialdeveloper