Is there a sure-fire way, no. It’s usually fairly clear however. Normally you call super if you override a method unless it tells you not to in the documentation or you are clearly trying to make something NOT do what the superclass did. I suppose my handwaving rule is if a method ‘does’ something and you override it to do more stuff as well, you probably still want the old stuff one, so call super (viewDidAppear: .. etc). If you are overriding a method which calculates and returns something, then unless you want the result super gives you as a starting point, since you are returning a calculation, you don’t want to call super (eg hitTest:withEvent:)
The docs for UIView’s drawRect: for instance tell you when to and when not to so some are documented to help you For those cases you list below, two of them are documented to throw exceptions, so you wouldn’t call them and the last one is a delegate method, so it doesn’t have a super. I know they were just examples you picked at random, but you can often come up with the right answer just by asking, what does the superclass method do, and do I still want it to do that. > On 12 Aug 2014, at 9:02 pm, McLaughlin, Michael P. <mp...@mitre.org> wrote: > > Is there a sure-fire way to know when it is necessary to call super in an > override? > > Sample code shows that calling super is necessary for methods such as > > -(id)init > > > - (void)windowControllerDidLoadNib > > > but not for > > > (NSData *)dataOfType > > > (BOOL)readFromData > > > How can you know for sure? > > > This question occurred to me recently when I realized that my implementation > of > > > (NSApplicationTerminateReply)applicationShouldTerminate > > > did not call super and I was wondering whether I should. Currently, I just > clean up and return NSTerminateNow. > > > Thanks for any reply. > > > > — > Michael P. McLaughlin > > _______________________________________________ > _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com