Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explain alternative signatures of @IBAction #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions content/ibaction-and-iboutlet.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,23 @@ And then you constantly have to dig into your .h file when playing with storyboa

Simplicity rules in swift. If you have a property defined that you want to make accessible to your storyboards, just add the `@IBOutlet` attribute before your property. Similarly with `@IBAction` to connect storyboard actions back to code.

The sender argument is optional. If you need it, and you know the sender's type, then specify it in the method signature. If you need the sender but it can be of different types you use `AnyObject`, which is the equivalent to the `id` type in Objective-C. For the cases where the sender is not interesting, just leave it out.

{{% prism swift %}}class MyViewController: UIViewController {
@IBOutlet weak var likeButton: UIButton?
@IBOutlet weak var instruction: UILabel?

@IBAction func likedThis(sender: UIButton) {
...
}

@IBAction func sendersTypeDoesntMatter(sender: AnyObject) {
...
}

@IBAction func dontNeedSender() {
...
}
}
{{% /prism %}}

Expand Down