Now I’m learning swift using Xcode, but I don’t know where to drag and drop and why drag and drop "label" to somewhere
should I drop no.1? or no.2? or no.3? and why I should drop there?
Now I’m learning swift using Xcode, but I don’t know where to drag and drop and why drag and drop "label" to somewhere
should I drop no.1? or no.2? or no.3? and why I should drop there?
3
Answers
If you drop it to 1, Xcode automatically generate an
@IBOutlet
for you. If you drop it to 2 or 3, then@IBAction
. There’s no other reason for that except that Xcode tries to be smart and help you organize code more nicely: properties with properties in the top of the class, methods – in the methods area. And you can also move declarations to another place later: except for code style matters, it doesn’t matter, where exactly within your class you put declarations.as you are trying to take an IBOutlet for a label , its nice to keep it on top of the class (where you mention 1).
normally Xcode gives suggestion you , if you drug on top side it will be
@IBOutlet
or you on bottom like 2 or 3 it will be
@IBAction
like you already took a button action in your code .Your Solution On Code:
If you want to own the label in your code, and then make some configuration to the label by code, use "1". It will give you a @IBOutlet label object in your code.
If you want to set the label’s action, use "2" or "3".