If you are a new visitor to our site, please read the Getting Started guide.

Say you created a brand-new Xcode project using the Single View Application template. Now, you want to change the viewController external file names and internal reference to the viewController class. You’d have to use Xcode’s Refactor file menu as shown below.

reforting-files-figh01

1. Click the viewController.h file to load it in the code editor window, then highlight the class name as shown in this image:

scrollview-refactor-step1

2. Choose EditRefactorRename. Xcode respond by displaying the window you see below. Enter MasterViewController in the box and leave the “Rename related files” checkbox checked. When you are done, click the Preview button.

scrollview-refactor-step2

3. Your screen will now look like this, which basically tells you where the Refactor operation will take place. Click the Save button.

scrollview-refactor-step3

4. On the last window Xcode shows you, just click the Enable button. Xcode goes to work to rename the class throughout the project. If you were to run the application now, it will work as expected by displaying a blank view in the iPhone Simulator window.

I want you to click the AppDelegate.m file and take a look at line 19. Notice the refactoring process did not change the initWithNibName: argument and the app ran without crashing. I don’t know why the app work considering the nib name’s is no longer ViewController. Feel free to change it to @”MasterViewController” and run the application once again. As you can see, the app still works.

Tags:

No responses yet

Leave a Reply

UIDocument Demystified: A Step-by-step Guide on Local and iCloud Document Storage

 

Archives