0

I am a Android developer ,Currently I was learning iOS development.And Confused about the target-action pattern. In android if i want to get a callback when a button clicked,I can do like this:

btn.setOnClickListener(myOnClickListener);

It's just like the delegate-pattern in iOS ,But Why Apple choose the target-action pattern for the gestureReconginer event handle?

Sorry for my poor english skill,Thanks you guys in advance.

Seth
  • 845
  • 8
  • 17

1 Answers1

0

Using target-action, you assign one method of one instance (=target) to one event (=action), whereas delegation would assign one instance implementing a dedicated protocol (equivalent to Java interface) to one event source that then calls the (maybe multiple) methods of that protocol-implementing instance.

I'm not sure anyone can answer why they did it this way, except a software designer/architect of Apple. Nevertheless, target-action has the potential of being transferable to closure syntax.

Andreas Oetjen
  • 9,889
  • 1
  • 24
  • 34