KexAri KexAri - 2 months ago 15
Swift Question

Cannot invoke initializer for type 'Selector' Swift 3.0

Since migrating to Swift 3.0 on this line :

let flexibleSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: self, action: Selector())


I have the error
Cannot invoke initializer for type 'Selector' with no arguments
. What am I doing wrong here?

Answer

Use this if you want to set an action:

let flexibleSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: self, action: #selector(test))

func test(){

}

Or if you don't want to set an action use:

let flexibleSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: self, action: nil)