I work with old project and in some part of the project, the naming convention is not good so I want to change it.
For example:
@property (weak, nonatomi
I put my two cents in. I tried to refactor several similar IBOutlet-s and ended to complete successfully only one - the first one.
All others outlets of this type throw me the error on refactoring:
Project and XCode reloading doesn't solve the problem. I checked *.xib source - the first one is fine: My XCode ver 9.2(9C40b)
New in Xcode 9 you can rename an outlet (or action) in the code and storyboard at the same time.
*DISCLAIMER: This feature only works in Xcode 9 (released September 2017) and above. Make sure to backup your project before using it. After making outlet name changes, test the affected screen(s) to make sure there are not issues. I tested this in a sample Objective C project successfully but it could cause problems in existing, more complex projects.
To rename an outlet...
@property (weak, nonatomic) IBOutlet UIButton *btnRequestCode;
@property (weak, nonatomic) IBOutlet UIButton *requestCodeButton;
This is what I usually do
3.Replace to the name you want
4.You can click Replace All if you are sure. You can also to click preview to Replace every single change
If you are using Xcode Version 9.0 (release 9A235 or earlier beta) and you don't want to crash at UIApplicationMain()
you will need to perform the following steps in order to rename an IBOutlet
instance variable. (see below)
Steps:
do
while ( untouched related .xib files exist)
I wasted hours trying to figure out why the app was crashing in UIApplicationMain()
after doing some mass refactoring of variable names. No logic changes, just hours of documenting, cleaning up structure for readability and just cleaning up names... not worth testing normally but when I decided to run.. BOOM
As it turns out, the (ahem) "release" of Xcode 9 does not manage to actually refactor IBOutlet instance variable names so you relegated to hand-jamming the .xib files. True refactoring would make all the necessary changes in the project...
Here is a regression tested example of how and what to do.
Example:
Select the IBOutlet
instance variable, then right-click, select Refactor -> Rename... :
(step 1 and 2)
Now change the name. (for the example from textFieldController
to editTextFieldController
) :
(step 3)
Now for the critical part that Xcode neglects, change the custom outlet property in the XML:
(steps 4, and 5)
and then find the original variable (eg textFieldController
) and change it to the new variable name (eg editTextFieldController
)
(step 6)
... and then when you compile and run, it doesn't throw an exception / assertion in UIApplicationMain()
...