2

Possible Duplicate:
Objective-C multiple inheritance

In my application, I need to add SideSwipeTableViewController and PullRefreshTableViewController to ViewController.h. However, for some reason, it will give me an error when I try to build the app.

Here is the code:

@interface ViewController : SideSwipeTableViewController, PullRefreshTableViewController  {

    ...

}

It works when either one is in, but not both. What I want to know is: is there a way to successfully implement these two classes? Thanks in advance and my apologies with the question: I'm still a bit new to Objective-C.

Community
  • 1
  • 1
chrisjr
  • 760
  • 3
  • 11
  • 18

1 Answers1

9

There is no multiple inheritance in Objective-C. You can implement any number of protocols though.

DrummerB
  • 39,814
  • 12
  • 105
  • 142
  • Oh. Well, how would I do that in relation to this? – chrisjr Sep 18 '12 at 23:20
  • 1
    Composition, not inheritance. The logic you want can be put into an ivar, for instance. – Jonathan Grynspan Sep 19 '12 at 00:02
  • 1
    @Junior117: that's an entirely separate question, and one that's much broader than you might think at first glance; I'd suggest you take a look at the Protocols section in [Apple's docs](https://developer.apple.com/library/mac/#referencelibrary/GettingStarted/Learning_Objective-C_A_Primer/_index.html) or look around for more info about protocols. – Tim Sep 19 '12 at 00:03
  • 2
    @Junior117 you'd use composition rather than inheritance. All of Java, Objective-C and C# reject multiple inheritance for a variety of reasons; Googling those terms should give you quite a lot of material on why. – Tommy Sep 19 '12 at 00:03