12

Possible Duplicate:
Objective-C multiple inheritance

I want to implement multiple inheritance in Objective-C i.e. I have a class "Sub" which needs to be a sublass of class "Super" as well as UITableViewController

How can I acheive the same in Obj-C?

0

2 Answers 2

22

Objective-C doesn't support multiple inheritance. You could use a protocol, composition and message forwarding to achieve the same result.

A protocol defines a set of methods that an object must implement (it's possible to have optional methods too). Composition is basically the technique of include a reference to another object and calling that object when it's functionality is required. Message forwarding is a mechanism that allows objects to pass messages onto other objects, for example, an object that is included via composition.

Apple Reference:

Sign up to request clarification or add additional context in comments.

1 Comment

This is a good idea !
5

There is no multiple inheritance in Objective-C. You can try to resolve what you need to with composition though.

Something like this:

@interface MyViewController : UIViewController {
    Sub *mySubComponent;
}
@property (nonatomic, retain) Sub *mySubComponent;
// you can write wrapper methods here to call mySubComponent methods/messages

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.