objective c - Why does respondsToSelector: exist? -


why have manually check every time try send message object might not respond message/selector? why can't language check every time message sent, or every time performselector: or variants of message gets called. eliminate crashes due sending invalid messages.

is inefficient this?

there few reasons why every method call doesn't have built-in check. first, pretty inefficient. more importantly, in cases should calling known methods there no need check.

but there various reasons why want check @ runtime. protocols optional methods prime case. working different versions of api common reason. new methods added or removed on time.

we need able tell difference between mistake , knowing calling method may or may not exist. when mistake, want failure , exception. when method optional, need runtime check call can skipped if doesn't exist.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -