Tuesday, March 20, 2012

Objective-C "abstract" base class

Once upon a time I needed to port some Java code from Android to Objective-C iOS.

Just wanted to share one useful tip on how to express the abstract class in Objective-C.

Basically in the "abstract" base class the "abstract" methods should be implemented like this, for example:


- (int) myAbstractMethod {
    [self doesNotRecognizeSelector:_cmd];    
    return 0;
}

Then the method should be implemented as needed in the concrete child class.

No comments: