AppCode 2022.2 Help

Extract property

The Extract Property refactoring lets you move expressions and local declarations to properties.

Extract property

Extract a property

  1. In the editor, select the expression or declaration you want to replace with a property.

  2. Press ⌃ ⌥ E or select Refactor | Extract/Introduce | Property from the main or context menu.

  3. If there are several expressions available for extracting, select the required one from the list that opens and press .

  4. Select a name for the property from the list of suggestions that opens or type a new one.

  5. If you want the property to be generated in a private category, select the Put to private category checkbox. Otherwise, the property will be declared in the header file.

  6. Press .

Code examples

Before

After

@interface LoginViewController () // ... @end @implementation LoginViewController { } - (void)performLogin { // ... [self.loginModel loginWithEmail:email password:password completion:^(BOOL success) { // success will be extracted to // a property if (success) { [self showAlertLoginSuccess]; } else { [self showAlertLoginFailed]; } }]; }
@interface LoginViewController () // ... // Extracted property @property(nonatomic) BOOL loginSuccessful; @end @implementation LoginViewController { } - (void)performLogin { // ... [self.loginModel loginWithEmail:email password:password completion:^(BOOL success) { self.loginSuccessful = success; if (self.loginSuccessful) { [self showAlertLoginSuccess]; } else { [self showAlertLoginFailed]; } }]; }
    Last modified: 26 August 2021