AppCode 2019.2 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

  • change the method/function return type

  • add new parameters and remove the existing ones

  • 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. Place 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 properties of the new parameter in the corresponding table row.

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

      • To reorder the parameters, use the Up (The Up icon) and Down (The down icon) icons.

  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) { // ... } }

Rename a function and its parameters

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

  2. In the dialog that opens, type a new name in the Name field.

  3. Click the parameter and type a new name in the Name field that appears.

  4. Click Refactor.

Before

After

// This function and its parameter // will be renamed BOOL isPasswordValid(NSString *password) { return password.length > 4; } - (void)performLogin { // ... // Function's call if (isPasswordValid(password) == NO) { // ... } }
// The changed function BOOL isIdValid(NSString *id) { return id.length > 4; } - (void)performLogin { // ... // Function's call if (isIdValid(password) == NO) { // ... } }
Last modified: 10 October 2019