Sunday, July 27, 2014

Nothing From Something - Missing 'Empty Application' Template

Is your latest version of Xcode missing the ‘Empty Application Template’? Are you feeling a little insecure about putting all of your eggs in the ‘Storyboard’ basket? (nudge, nudge, wink wink)

Starting with an empty app is a great way to learn iOS programming. With just the AppDelegate and a couple frameworks, you can create the view controller classes programmatically and really gain an understanding of what happens ‘behind the scenes’. It remains to be seen whether Apple will permanently force the issue of Storyboards, however, If you find yourself wanting to start your project without using Storyboard to create your view controllers, you have a couple easy options.

Option 1:

- Start with a single view application. Select File > New > Project > Single View Application.

- Fill in the project options. For this example, select Objective-C for the language.

- In the project navigator, delete the ViewController.h, ViewController.m and Main.storyboard files that were created by the template. Select the ‘Move To Trash’ option when prompted.

- Select the Info.plist file inside the Supporting Files folder. Near the bottom is a key named ‘Main storyboard file base name’. Hover the cursor to the right of the key name. When the ‘plus / minus’ signs pop up, click the minus sign to remove the reference to the storyboard.

- In the project navigator, highlight the project name at the top and select Build Phases > Link Binary With Libraries. Add the Foundation, UIKit and CoreGraphics frameworks to the project.

Now, in the AppDelegate.m file, replace the method body of ‘didFinishLaunchingWithOptions’  with the following code:


self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;


You now have the equivalent of an Empty Application Template. After the ‘Override point’ comment, you can instantiate you’re root view controller class.

Option 2: Copy and paste the empty application template file from Xcode5.

- Control-click the Xcode.app icon in the Applications folder and select ‘Show Package Contents’.

- Navigate to the following folder: Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Templates/Application

- Copy the folder titled ‘Empty Application.xctemplate’.

- Navigate to the following folder: (In the > Xcode5 app): Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Templates/iOS/Application

- Paste the copy of the template in this location.

The ‘Empty Application Template’ will now be available when you select File > New > Project > …


I hope this is helpful. I saw several posts where users were wondering what had happened to the ‘Empty Application’ template. Look forward to a future post on creating custom templates.

No comments:

Post a Comment