Introduction to a series of articles detailing how to implement a new type of Swift Local Refactoring.
So you thought about contributing to Swift code base but never knew where and how to start? Well then, Swift Local Refactoring is a very good place to start.
In a series of articles I’ll take you through my experience with implementing a single local Swift refactoring action. The refactoring action I chose as an example is “Collapse Nested If Statements”.
In short, it changes code like thisinto thisThe steps:
- Setup Swift build environment.
- Follow TDD approach and Write tests first.
- Implement Part 1 refactoring action.
- Implement Part 2 refactoring action.
- Debug the code.
- Summary and my thoughts on Xcode’s refactoring feature.
You may notice that Collapse Nested If Statements refactoring action is already implemented and available in latest versions of Xcode.
A disclaimer though, I did not implement that action, but I surely took learnings from the current implementation.
The major difference between an action currently available in Xcode and the one described in these articles, is that current Xcode’s version collapses only 2 statements at a time, so if you have 3 or more nested statements, you have to repeat the action to collapse them all.
(Reload to play gifs)
While the action implemented in these articles collapses all nested if statements at once.