xcode - When do we need button to send argument in Swift? -


when connecting button in xcode @ibaction func, can choose between arguments: sender or none.

when choose sender , when none?

well, if action method needs know button triggered it, or can make use of of button's properties, need pass sender (the button) method.

a contrived example if have calculator, has '+' , '-' button. both share action method performcalculation(sender: nsbutton) , method use sender's symbol (this button's title) perform correct calculation.

on other hand, if have button, example clear input on textfield, wire button method clearinput() not need have information button triggered (in fact, having no argument here make easier reuse method elsewhere in code , trigger clearing textfield programmatically).

i hope makes sense you. there no clear rules afaik. it's matter of taste guess.


Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -