News Tips & Tricks

AppCode 2020.2 Beta Brings Change Signature Refactoring for Swift!

Hi everyone,

AppCode 2020.2 release is just around the corner, and our first Beta build delivers an initial implementation of the Change Signature refactoring for Swift! Let’s take a closer look at it.

When you need to change the signature of a method, the usual flow is to rename all the method parts separately, such as parameter names, internal parameter names, and the method name itself. This already makes for too many repeated Rename refactorings.

But what if you need to also change the method return type, or the type for one of the method parameters? What if you need to also change the method visibility? The only way to do this is to go in and manually change the code. This is where the Change Signature refactoring comes in, helping us perform all these tasks at once, automagically.

Press ⌘F6 or select the Change Signature refactoring from the Refactor this popup (⌃T). If you are trying to change the signature of an overridden method, AppCode will ask if you want to change the base method together with overridden ones, or only the overridden method:

Base or current method

In the dialog that opens you can rename the method itself, change its visibility, change internal and external parameter names, and add or delete parameters:

Change Signature controls

You can invoke this refactoring from any method usage in the project – not necessarily from its declaration. When adding a parameter, specify its default value. Check Optional if you want it to be added to the method signature, or leave as is to insert the value to each method call:

Add parameter

What if you need to “just” reorder init method parameters in the whole project? Press ⌥↑/⌥↓ in the Change Signature dialog:

Swap parameters

Click OK to perform the refactoring, and AppCode will change all method occurrences in your project.

Try Change Signature today and share your feedback with us here in the comments! Also, if you are interested, you can read about other Swift refactorings in our blog.

Your AppCode team
The Drive to Develop