Objective-C equivalent of "override" in C#

All class and instance methods in Objective-C are dispatched dynamically and can be overridden in subclasses. There is nothing like C#'s override keyword, or like its virtual keyword.


Yep - it's definitely possible. There's no override keyword though. Just declare a function with an identical signature in your subclass, and it will be called instead of the superclasses version.

Here's what Airplane's startEngine method might look like:

- (void)startEngine
{
    // custom code

    // call through to parent class implementation, if you want
    [super startEngine];
}

All methods in Objective-C are overrideable, you just write a method for the same signature.

Tags:

Objective C