Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Simple iPhone App with Swift 2.0 View Controllers and Views Designing With Interface Builder

Relation between controller class name, storyboard ID, and view controller scene title

I'm getting a little mixed up with all the naming of objects in an app.

What is the relation--if any--between the class name (in Identity Inspector), the storyboard ID (in Identity Inspector), and the view controller scene title (in Attributes Inspector)? Are there any naming conventions for these three?

1 Answer

Steven Deutsch
Steven Deutsch
21,046 Points

Hey Christine Chang,

The roles of these 3 components in Interface Builder are as follows:

1) Storyboard ID - Identity Inspector tab

The storyboard ID is used to identify a specific scene on the storyboard. This is commonly used with the UIStoryboard class to instantiate a view by using it's storyboard identifier.

// Example using Storyboard ID
let myStoryboard = UIStoryboard("Main", bundle: nil)
let myViewController =  myStoryboard.instantiateViewControllerWithIdentifier("StoryboardID")

2) Class - Identity Inspector

The Class listed inside of the identity inspector is used to link a view in the storyboard to it's backing code file. You want to make sure all your views controllers in the storyboard are linked to their proper ViewController file. Anytime you make a custom subclass of an object in interface builder you want to make sure you link that object with the corresponding subclasses file. If you can't drag your IBOutlets/IBActions from the view into that file, you know they are not linked properly.

3) View Controller Scene Title - Attributes Inspector

The view controller scene title is a way to name your view controller inside of the storyboard. It changes the name listed for that view controller in the Interface Builder view hierarchy column. It can help you keep track of your view controllers while navigating this menu on a larger project.

Good Luck

Thanks, Steven!

So just to confirm...a single controller scene always corresponds to a single controller class, right? Or can one scene have multiple controller classes?

Steven Deutsch
Steven Deutsch
21,046 Points

Right 1 scene to 1 view controller file. The view controller scene in interface builder is just the visual representation of that view controller. The file has the actual implementation and functionality. It's possible to create all your UI elements programmatically inside of the view controller file itself, but using interface builder is much quicker.

Ah, I see, thanks! :)

On the flip side, is it possible to have a controller scene in interface builder and no corresponding code file for that controller? If so, in what situations would you do that?

Steven Deutsch
Steven Deutsch
21,046 Points

It would be possible but I can't think of a use case, because that view would have no functionality. Once it's presented the user wouldn't be capable of any interactions or dismissing the view controller. They would have to close and restart the app.