user3740953
user3740953

Reputation: 97

How to properly create a storyboard in xCode6 using Interface Builder and Swift

I need help using Interface builder to create a storyboard and initial view, using xCode 6 and Swift. I do not want to start with the template "Single View Application" but with an "Empty Application" - for learning purposes.

I am starting with File->New->Application in xCode 6. In the left pane I have selected iOS-> Application and I am choosing the template "Empty Application"

So now, I have my empty application and I want to use Interface Builder to create a story board.

I select File-New-File - then in the left pane I select iOS-User Interface and in the right pane I select Storyboard. I call my storyboard "Main"

That seems to do nothing, so then upon examining other templates, I decided that I need to go to info.plist and add a key/value pair, and so in info.plist I added a key "Main storyboard file base name" and a value of "Main"

After that I get the error:

Failed to instantiate the default view controller for UIMainStoryboardFile 'Main' - perhaps the designated entry point is not set?

So now I go to the story board and drag and drop a "View Controller" onto the storyboard, and btw - in the View controller inspector it is checked "initial scene - Is Initial View Controller"

But this doesn't create any swift file - which may be expected, but just to be clear it doesn't. Now when I try to run, I get the error:

Application windows are expected to have a root view controller at the end of application launch

So any ideas? I am trying to figure out how you properly use Interface Builder to create a storyboard and initial view and do a basic hello world, without skipping past the use of the tool to have it created for me in a template, because my assumption is you will quickly have more complex apps than can be created from a template, and it might be good to know how to use the tools - but I am not finding documentation on the subject.

Edit: strange timing I happened to find the answer just as someone else had also correctly answered the issue for me, so I will edit this post and remove the answer - as the answer below is exactly correct.

Upvotes: 4

Views: 4137

Answers (1)

rdelmar
rdelmar

Reputation: 104082

The storyboard automatically creates the window and instantiates the initial view controller for you. The code in the app delegate is creating another window which you don't want. You should delete all the code in didFinishLaunchingWithOptions, except for "return true". It will then run properly.

Upvotes: 3

Related Questions