2

I'm messing around with the storyboard builder and watching the viewcontroller as I do, so I can learn the code for each item. For example if I use storyboard to create a label I want to see the label code that is generated so I can document the code and learn to do it programmatically too.

The problem is that when I do create something there's no code to accompany it, do you know how I can see this so I can document the code as I go?

1 Answers1

1

Storyboards are nothing more than XML data. If you're using storyboards, there is no "Code" per-se that controls any of the functionality. The XML simply serves as directions for "This button goes here, that label there." and that's it.

The code begins when you start referencing views inside of swift files. That's using things such as @IBOutlet and @IBAction which are added to their class files associated with the views. For example, if you have a UIViewController that is associated with ViewController.swift then you add your buttons to that swift file via an Outlet typically this is done by opening both the Storyboard and the Swift file (I usually do it by pressing the hotkey while on the storyboard, CTRL+OPTION+CMD+ENTER) and then Control+Click/Drag to the swift file. It will prompt you for an @IBOutlet or an @IBAction and then post the relevant code.

What is @IBOutlet? Well, in layman's terms, it's the variable that references that button from the XML in code so that it can be used.

What is @IBAction? It is essentially the same thing as an @IBOutlet however it has an Action associated with it. For example, a button can have both an @IBOutlet and @IBAction` the outlet will allow you to modify things like the view, color, text, title, label, and any property of the button. The action on the other hand will allow you to "Run XXX block of code when that action is triggered.

xTwisteDx
  • 2,152
  • 1
  • 9
  • 25