AppCode 2020.1 Help

Change signature

The Change Signature refactoring combines several different modifications that can be applied to a method/function signature. You can use this refactoring to:

  • change the method/function name and return type

  • add, remove, and reorder parameters

  • change parameter names and types

When changing a method/function signature, AppCode searches for all usages of the method/function and updates all the calls, implementations, and override replacements of the method/function that can be safely modified to reflect the change.

Changing a method/function signature

  1. Position the caret at the name of the method/function that you want to refactor.

  2. Press ⌘F6. Alternatively, select Refactor | Change Signature from the main menu or from the context menu.

  3. In the Change Signature dialog, make necessary changes to the method/function signature depending on your needs:

    • Change the type of a callable procedure. In the Callable Type, select Function, Method, or Block.

    • Change the method/function name. To change the name, edit the text in the Name field.

    • Change the method/function return type by editing the contents of the Return type field.

    • Manage the method/function parameters. To configure the parameters, use the table and the buttons in the Parameters area:

      • To add a new parameter, click The Add button and specify the new parameter's properties in the corresponding table row.

      • To remove a parameter, select any row and click The Remove button.

      • To reorder the parameters, click The Up icon and The down icon.

  4. Click Refactor.

    Change signature refactoring
  5. To see the expected changes and make adjustments prior to the refactoring, click Preview.

Examples

Convert a function into a block

  1. Place the caret at the isPasswordValid function and press ⌘F6.

  2. In the dialog that opens, select Block in the Collable Type list.

  3. Click Refactor.

Before

After

// This function will be converted into a block BOOL isPasswordValid(NSString *password) { return password.length > 4; } - (void)performLogin { // ... // Function's call if (isPasswordValid(password) == NO) { // ... } }
- (void)performLogin { // ... // New block if (^BOOL(NSString *password) { return password.length > 4; }(password) == NO) // ... }

Rename a method and swap its parameters

  1. Place the caret at the setupTextFiled method and press ⌘F6.

  2. In the dialog that opens, select the field parameter and click the Move down button.

  3. Change the authomatically created method's name from setupTextIsValid to setTextFieldIsValid:

  4. Select the field parameter and rename its name and selector part to textField.

  5. Click Refactor.

Before

After

// This method will be renamed, // and its parameters will be swapped and renamed. - (void)setupTextFiled:(UITextField *)field isValid:(BOOL)isValid { // ... } - (void)performLogin { // ... // Method's call [self setupTextFiled:self.textFieldPassword isValid:NO]; }
// The changed method - (void)setIsFieldValid:(BOOL)isValid textField:(UITextField *)textField { // ... } - (void)performLogin { // ... // Method's call [self setIsFieldValid:NO textField:self.textFieldPassword]; }
Last modified: 5 June 2020