Adam Carter
Adam Carter

Reputation: 4844

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!

Upvotes: 0

Views: 200

Answers (2)

Kjuly
Kjuly

Reputation: 35131

a class which held a set of custom CABasicAnimations.

In this case, I'd like to use Category instead of Subclass.

Upvotes: 1

sosborn
sosborn

Reputation: 14694

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.

Upvotes: 3

Related Questions