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.