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
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")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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With