Search code examples
objective-cclassnsobjectsuperclass

Using a different Superclass, instead of NSObject


This might be a straight forward answer, and I know that you don't have to set NSObject as the Superclass when creating a new class.

But say, for example, I wanted to create a class which held a set of custom CABasicAnimations. Although it may be perfectly ok for me to use CABasicAnimation as the superclass, is it recommended that I follow the unwritten rule and still use NSObject or would you, if you were writing such a class, use CABasicAnimation as the Superclass?

I would assume that it wouldn't matter as long as the Class only contained properties and methods relative to CABasicAnimation.

It would be interesting to here your thoughts!


Solution

  • The rule is to subclass whatever object you are trying to extend. NSObject is used for many subclasses because it is the root object, but if I was going to write a class that was very similar to NSTableView, then I would subclass NSTableView.

    In your case, if you are writing a custom animation that you want to call, then you should consider subclassing from CABasicAnimation. On the other hand, if you animation is really just a collection of pre-exisiting CA animations, then NSObject would be fine.