Objective-C convention for overridden methods

In Java, when you override a method, you are advised (almost forcefully) to add the @Override annotation. Is there an agreement on marking (in comments or any other mechanism) overridden methods in the Objective-C world?

+7
source share
3 answers

Not. All methods in Objective-C are sent via Objective-C messaging, so all methods can be overridden. This part of the tongue.

There is no agreement for labeling. This is part of the language in which it occurs, and if you were to comment differently, it is simply confusing when you do it later, by accident or intentionally.

+3
source

No, not at all.

This does not seem to matter as much, possibly due to dynamic dispatch.

+1
source

I'm not sure if Xcode does this, but Jetbrains' AppCode IDE automatically annotates overridden methods with a blue override symbol in the field, for example:

Appcode override

., In addition to this (also shown), I would also like to create some live templates (aka snippets of code in Xcode) to annotate overridden methods with the #pragma tag. I find this helps determine the standard structure in the following order:

  • class methods
  • initialization and destruction
  • public methods / protocol methods
  • overridden methods
  • private methods

as well as the presence of patterns / snippets of code on the Internet. I can simply enter "override [tab]" and the IDE will create the #pragma tag for me.

. maybe you can even use OCLint to check if this structure is being followed.

+1
source

All Articles