Hi,
I'm very curious - why does UITextInputDelegate
have all its methods required? Why can't I just implement the one I want (for example textDidChange
)?
views:
52answers:
3
A:
For me it looks like some apple engineer was too lazy to program the delegate calls properly. So he just didn't set the @optional so he doesn't have to deal with methods that probably not exist.
V1ru8
2010-08-18 15:20:08
deleted........
JeremyP
2010-08-18 15:30:45
i don't think that's it.
Merlin
2010-08-18 19:25:14
If that were the case I am sure Apple would have fixed it, after all changing delegates to optional is not going to break existing code.
Simon
2010-08-19 07:19:16
Well what happens when your existing code calls an optional method that is not implemented? It will crash! You have to check optional methods if they're there. You don't have to do that on required methods! (see @JeremyP's argument)
V1ru8
2010-08-19 07:52:15
yeah, but I don't think laziness has anything to do with it.
Merlin
2010-08-19 14:35:05
yeah, yeah, maybe they have some reason for doing it. Who knows.
V1ru8
2010-08-19 15:50:55
A:
It might be a performance thing. These methods are called frequently and it's quite a big performance hit to have to send -respondsToSelector:
every time anything changes.
JeremyP
2010-08-18 15:32:19
Could be, but you don't have to call respondsToSelector on every call. You could check that only when the delegate changes. This even might be faster because then you only compare to a boolean which I assume is faster then calling an empty method.
V1ru8
2010-08-18 16:13:43
so mystery remains :) I'm approving this answer because it sounds reasonable.
Merlin
2010-08-18 19:27:20
Thanks Merlin. Just to be clear, the answer is just speculation. I don't have any secret information from Apple.
JeremyP
2010-08-19 08:15:26
A:
Can't you just make empty funcs for the three methods you don't need?
ExitToShell
2010-08-18 17:29:37