Are actions (@IBAction) considered outlets in Swift?

Hello,

I'm using a tutorial book to learn app development for iOS and I have a question regarding the wording in the instructions of the book. In the book, I am asked to create a method for a "Start Over" button in a game. That method can be seen below:

    @IBAction func startNewGame() {
    score = 0
    round = 0
    startNewRound()
}

But then, the book says "Connect the outlet". I'm confused as to why it's referring to the action @IBAction....startNewGame() as an "outlet". Is an @IBAction method an outlet or an action? Or both? Please help. I can't tell if it's a typo, or if actions are also outlets. Thank you.

It's referring to the button itself, because you are connecting the button to the action method. It's somewhat confusing terminology with IBOutlets which are instance properties in your code that get connected to Interface Builder objects. The drag directions are opposite for each. Drag from IB object to code to connect an action. Drag from the object property marked with IBOutlet to the IB object to connect.

1 Like

Thank you for this clear explanation. I get it now! :slight_smile:

Terms of Service

Privacy Policy

Cookie Policy