Reputation: 3289
I searched a lot for selector method in Swift 3, but I have lots of confusion for it.
1) what is difference between Selector
& #selector
?
2) if I write with Selector
, the function is outlined means not available?
3) How to pass a parameter with #selector
method.
My code
let button = UIButton()
button.addTarget(self, action: #selector(getData(_:true)), for: .touchUpInside)
button.addTarget(self, action: Selector(), for: .touchUpInside)
func getData(_ isShowing:Bool){
}
Can you help me to clear my confusion?
Thank you for your valuable time
Upvotes: 3
Views: 2937
Reputation: 4174
Answers to your questions:
#selector
--> will return Selector
type. #selector
checks if there is any function exist with that function namebutton.layer.setValue(forKey:"someKey")
Upvotes: 3
Reputation: 5195
I believe #selector
is just a language construction that creates an object of type Selector
. You want to use #selector
as the compiler actually checks if the method exists anywhere, where with Selector("abc")
you just run the constructor and it's not validated.
Upvotes: 1