Extract property
The Extract Property refactoring lets you move expressions and local declarations to properties.
Extract a property
In the editor, select the expression or declaration you want to replace with a property.
Press ⌃ ⌥ E or select Refactor | Extract/Introduce | Property from the main or context menu.
If there are several expressions available for extracting, select the required one from the list that opens and press ⏎.
Select a name for the property from the list of suggestions that opens or type a new one.
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.
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