Using Xcode 6 with the 4th Edition book

As many of you have already experienced, Xcode 6 has changed a bit compared to Xcode 5 which could cause some confusion as you go through the book.

[size=150]Xcode 6[/size]

[size=130]Empty Application Template[/size]
This is the biggest problem. There is no longer an “Empty Application Template” which we use throughout the book. The steps you’ll want to go through instead will be:

[ol]
[li]Create a new project[/li]
[li]Select the “Single View Application” template[/li]
[li]Delete the the files Main.storyboard, ViewController.h, ViewController.m[/li]
[li]Go into your project settings (Command+1, then click on the project name at the top), and delete the text “Main” under “Main Interface”[/li]
[li]Open AppDelegate.m and add in the missing window code. Your application:didFinishLaunchingWithOptions: method should look like:

[code]

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];

    return YES;
    }
    [/code][/li][/ol]

[size=130]XIBs[/size]
XIBs now have square views by default due to something new called Size Classes. When laying out interfaces, especially before getting to the Auto Layout chapters, you’ll probably want the view to be the same size as the screen it’ll be running on. To get the views the correct size:

[ol]
[li]Open the XIB[/li]
[li]Open the Attributes inspector (Command-Option-4)[/li]
[li]Change the Size under Simulated Metrics to the size of the device you’ll be running on. The book uses the iPhone 4-inch option, but if you are running on a different simulator or device, select that. Just be consistent and make sure you are running on the same device that the XIB is configured to look like, else you might have subviews that aren’t visible due to being off screen.[/li][/ol]

[size=130]Simulator Keyboard[/size]
With Xcode 6, the simulator now acts more like an actual device when it comes to the keyboard. By default, selecting a text field will not display the on-screen keyboard; instead, it uses your computers keyboard as if it was an external keyboard controlling the app (so the on-screen keyboard isn’t necessary). To get the existing behavior, you’ll want to “Toggle Software Keyboard” (Command-K) from the “Hardware -> Keyboard” menu (http://cl.ly/image/1P351M3M0w0W).

[size=150]iOS 8[/size]

If you’re building on iOS 8, you may notice some problems as well. I’ll update this post as problems are discovered.

[size=130]Chapter 6: View Controllers[/size]

[size=120]Adding a Local Notification[/size]
In iOS 8, local notifications require user authentication just as push notification do. To address this issue, add the following code to your AppDelegate’s application:didFinishLaunchingWithOptions::

UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert
                                                                             categories:nil];
[application registerUserNotificationSettings];

I’m up to the Subclassing UIView part of chapter 4. I’m supposed to make a new Objective-C class, but with xcode 6 this option doesn’t seem to exist. Should I go instead with a “Cocoa Touch Class” or an “Objective-C File”? Cheers.

Cocoa Touch Class, then make sure Objective-C is selected on the next screen.

Hi,

about the “empty application”: When I delete the text “Main” under “Main interface” it keeps coming back. It seems like it cannot be left empty - is there any fix to this?

Thanks :slight_smile:

[quote=“heikomania”]Hi,

about the “empty application”: When I delete the text “Main” under “Main interface” it keeps coming back. It seems like it cannot be left empty - is there any fix to this?

Thanks :slight_smile:[/quote]

What version of Xcode are you using? I’ve heard of others having this problem, but I cannot reproduce under Xcode 6.0.1.

[quote=“ChristianKeur”][quote=“heikomania”]Hi,

about the “empty application”: When I delete the text “Main” under “Main interface” it keeps coming back. It seems like it cannot be left empty - is there any fix to this?

Thanks :slight_smile:[/quote]

What version of Xcode are you using? I’ve heard of others having this problem, but I cannot reproduce under Xcode 6.0.1.[/quote]
6.0.1 as well. But never mind, I installed Xcode 5 as well so I can use the book.

It isn’t better to work with Xcode 5, for follow along with the book?

Regards.

I was pulling my hair trying to figure out what to do before reading this post!

Thanks!

Regarding the empty application template disappearing in Xcode6 , I found a workaround :

Download the empty application template from here : cl.ly/401z1t1R1b3Z

then copy over the contents of the zip file to here : {Xcode.app}/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Templates/iOS/Application/

This worked for me :smiley:

Credit goes to reddit post : reddit.com/r/iOSProgramming/ … on_option/

Thanks, that template actually works for me as well!

Hi,

I’ve noticed that I often need to explicitly add a “#import <UIKit/UIKit.h>” to a lot of examples. Is this expected because I’m using XCode 6?

Thanks.

Can someone please explain to me where the “Main” is I have to delete? Following the instructions yielded nothing that says “Main” anywhere. The only place I do see it says “Main storyboard file base name”. Is this the place to delete it?

Also before anyone suggests I cannot use the template listed at the bottom (due to work reasons).

To keep the context handy, the applicable instructions from the original post in this thread are:

So yes, the file Main.storyboard does exist as one of the files in the project. (Assuming, of course, that Xcode6 is being used.)

For item #4, in the project settings (via cmd+1 then click the project name at the very top of the list in the left sidebar, the one with the Xcode icon; it may say “2 targets” right below the name), the second section in the main display area is labelled “Deployment Info”. Clear the text “Main” from the text field that has label “Main Interface”.

Just curious Christian, it seems that Apple is quite insistent on the use of Storyboards by making it tedious for developers to avoid its use. All iOS 8 tutorials such as Ray Wenderlich and AppCoda are also using Storyboards. I’ve also read the debates here: http://stackoverflow.com/questions/9404471/when-to-use-storyboard-and-when-to-use-xibs and personally, I do love the approach by BNR. I’ve never liked storyboards as I tend to get lost visually by the implementation.

Will BNR position on storyboards change should the 5th edition of the book be released? All my projects have avoided the use of storyboards, and I’m afraid that I may have to migrate to the Storyboard version.

I’m working out of the iOS7 BNR book and there too they show empty application examples.

So far it does not work to delete the story board because when you create a new on there is no reference to it in Xcode anymore.

You get an error 2014-12-04 13:33:05.372 TestOfUsingNewStoryboard[32741:1681621] Failed to instantiate the default view controller for UIMainStoryboardFile ‘Main’ - perhaps the designated entry point is not set?

Also when you drag in a ViewController there is no arrow pointing to it so it does not exist, you can’t drag anything onto it and then create an outlet or connect an action it’s dead in the water.

I tried deleting the reference to Main as suggestion made no difference. The issue is deleting the singleview template storyboard does something to cut ties with any new storyboard you create. Any guidance?

That said, I used a singleview template and just used the templated storyboard and renamed it. Also then created new class files (cocoa touch) and named them as in the book and then it worked at least for the multi-view app in chapter 6

So I am not clear yet what exactly the form of the empty app was.

[quote=“lc94114”]Hi,

I’ve noticed that I often need to explicitly add a “#import <UIKit/UIKit.h>” to a lot of examples. Is this expected because I’m using XCode 6?

Thanks.[/quote]

Apparently Xcode 6 no longer includes a certain file that included the UIKit import.

I found the answer here: http://stackoverflow.com/questions/26285381/cannot-access-uiimage-class-without-importing-uikit-h-in-xcode-6.

You must also.

  1. Delete LaunchScreen.xib
  2. change info.plist settings
    a) open Supporting Files -> info.plist
    i) set [color=#00BFFF]Launch screen interface file base name[/color] to [color=#00FFFF]QuizViewController[/color]
    ii) if there is a [color=#00FFFF]Main nib file base name[/color] there to set that to [color=#00FFFF]QuizViewController[/color]

Working with Xcode 6.1.1 now info.plist needs to be updated as well.

There is a row titled “main storyboard file base name” which contains “main” by default. I deleted “main” and left it blank and everything worked fine whereas before it was throwing an exception that it could not find a storyboard named “main”.

I did not need to delete LaunchScreen.xib or change anything else other than what was mentioned in the first post in this thread.

So if you download the solutions zip and go to run the storyboard build (and others) you get a linker command failed error.

What is the reason for that, and is there a simple solution?

Thanks

I am using IOS programming 4th addition and I currently have Xcode 6.1.1-is there a way to downgrade to 5.0.2 in order to make following along in the book a little easier?