"Missing argument for the style parameter in the call 'error in creating UIBarButtonItem system

I don’t understand why the compiler requests the argument of the style parameter in this initializer UIBarButtonItem in the system style - it does not have this parameter in the first place. Help? Is this a bug with Swift?

class ExpensesViewController: UIViewController { lazy var newExpenseBarButtonItem = UIBarButtonItem(barButtonSystemItem: .Add, target: self, action: Selector("newExpenseBarButtonItemTapped:")) func newExpenseBarButtonItemTapped() { } } 
+5
source share
4 answers

This will delete the compiler error message:

 class ExpensesViewController: UIViewController { lazy var newExpenseBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.UIBarButtonSystemItemAdd.value, target:self, action:Selector("newExpenseBarButtonItemTapped:")) func newExpenseBarButtonItemTapped() { } } 

.Add not a valid value

+3
source

No need to add the verb Selector for action.

 class ExpensesViewController: UIViewController { lazy var newExpenseBarButtonItem = UIBarButtonItem( barButtonSystemItem: UIBarButtonSystemItem.Add, target:self, action:"newExpenseBarButtonItemTapped") func newExpenseBarButtonItemTapped() { } } 
+3
source

If you use self in the scope of the class, you will get many strange compiler messages. It seems that the fast compiler is not growing up yet. The following code works fine with me on Xcode Version 6.1.1 (6A2008a).

 class Foo { var playButton:UIBarButtonItem? = nil func initButtons(){ self.playButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Play, target: self, action: Selector("doPlay:")) } } 
+2
source

I was able to fix this by making the button implicitly expanded and then initializing it later.

-1
source

Source: https://habr.com/ru/post/1201397/


All Articles