问题
In converting from Swift 2.3 to Swift 3, I receive the error above for the following line of code:
var contactButton: UIBarButtonItem {return self.CustomRightItem("icon-nav-nls-contact", target: self, action: nil)}
The problem is on the nil
action. I've tried using and empty selector: #selector()
and ```#selector(nil) both to no avail.
How can I handle a nil action in Swift 3?
回答1:
This is clearly placeholder code for a later action, so use a placeholder function where the code will eventually go and then call that selector as required with: #selector(functionName(_:))
Your full code will look like this:
var contactButton: UIBarButtonItem {return self.CustomRightItem("icon-nav-nls-contact", target: self, action: #selector(contactAction(_:)))}
func contactAction(_ sender: AnyObject) {
return
}
来源:https://stackoverflow.com/questions/40431812/nil-is-not-compatible-with-expected-argument-type-selector