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

@IBAction vs button.addTarget() #41

Open
jpmendel opened this issue Jun 18, 2018 · 2 comments
Open

@IBAction vs button.addTarget() #41

jpmendel opened this issue Jun 18, 2018 · 2 comments

Comments

@jpmendel
Copy link

When it comes to assigning actions to views we can interact with, which method of binding that action is better to use?

XIB File -> Connect to Code

then

@IBAction func buttonPressed(_ sender: UIButton) {
    // do stuff
}

OR

button.addTarget(self, action: #selector(buttonPressed(_:)), for: .touchUpInside)

then

@objc func buttonPressed(_ sender: UIButton) {
    // do stuff
}

The first we can only do if we use .xibs or storyboards, but if both are available, which is preferred?

@alexpersian
Copy link

XIB File -> Connect to Code
This is the preferred strategy for binding actions.

We often work without storyboards, but it's not often that we work without .xib files. If you're on a project that only uses programmatic view layouts then I think the convention whould be set for that project specifically.

@alexpersian
Copy link

Reopening because this is likely something we should define in our style guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants