Settingup Xib in XCode6,Xcode7 : Removing storyboard and setting up xib.

There is still a significant number of people who prefer Xib over Storyboard though i wont get into debate which one is better but still there might be some who would want to develop using Xib.From XCode 6 onwards Apple has removed the option to create an empty application. While creating a new project you are presented with 5 options.

1.Master-Detail Application

2.Page-Based Application

3.Single-Page Application

4.Tabbed Application

5.Game

As in image below

We will start with single view application,It automatically creates a main.storyboard and LaunchScreen.storyboard. You will start with single view application and you will remove storyboard and add xib to the application.

Create your application

and click next. You can have any name but for the ease of following please use same names.

Now when you see the navigator you will see LaunchScreen.storyboard and main.storyboard.

Select LaunchScreen.storyboard and delete it

Similarly delete the main.storyboard.

You are good to go done now..  Just kidding it will not compile.

The default single view is setup to load main.storyboard and since we have deleted it it will lead to crash.So now we need to remove the instruction which indicates loading of main.storyboard. Its in info.plist. You need to delete following properties from info.plist file

1.Main storyboard file base name

2.Launch screen interface file base name

After deleting these two properties your application does not load any UI  right now.

Now we will create a Xib file to go with our app.Lets create a xib file connect it to our ViewController and load it as root.

add new file to the project and from resulting interface choose User Interface and select Empty file

Name it ViewController.Now in navigator you will see your ViewController Xib file click on it.You wont see any view in interface editor yet.Drag and drop a UIView from object gallery into the interface editor.Now select your File Owner and from Identity Inspector change its class to ViewController. Once you have changed the class of file owner to ViewController connect the referencing outlet of view to fileowner’s view property as in image below

We are almost done. Now we have to make our ViewController root.

We will add following code in

[code]- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions[/code]

[code]

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

    self.window.rootViewController=[[ViewController alloc] initWithNibName:@”ViewController” bundle:nil];

    [self.window makeKeyAndVisible];[/code]

Now once you run you application in simulator you will see your ViewController as root.(I have changed the background color)

So that’s it guys it was that simple.    

A pat on the back !!