iphone - What's the difference between these Objective C method styles? -
there seems 2 standard ways of writing methods in objective c, , can't quite grasp difference , why 1 used rather other. example, uiwebviewdelegate:
- (void)webviewdidfinishload:(uiwebview *)webview { } - (void) webview:(uiwebview *)webview didfailloadwitherror:(nserror *)error { }
why isn't second 1 written webviewdidfailloadwitherror, or why doesn't first 1 match second style?
another example, time uitableviewdatasource:
- (nsinteger)numberofsectionsintableview:(uitableview *)tableview { return 1; } - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { return 0; }
how come numberofsectionsintableview doesn't follow same format other methods?
i'm sorry if simple question - it's been bugging me while , i'd clear in head!
thanks in advance help.
it comes down number of arguments. pretty every delegate method passes sender of method first argument. if method not need further arguments, method signature in first style, otherwise in second, following cocoa convention name each argument.
unfortunately, not possible append more text method signature after last argument. if were, sure apple rather name method - (void) webview:(uiwebview *)webview didfinishload
.
edit: there interesting discussion here on stack overflow on history of syntax decision: why must last part of objective-c method name take argument (when there more 1 part)? brad cox, creator of objective-c, chimed in.
Comments
Post a Comment