sali
sali

Reputation: 179

multiple inheritance from classes

My main class inherits from two other classes . First my main Class :

class login: customMessage,BaseViewController ,UITextFieldDelegate  {
...
}

which baseViewController inherits from UIViewController .

Then I have customMessage class which inherits from UIViewController too . Both of the classes need to inherits from UIViewController and When I inherit both of them at the same class , It gave me this error :

multiple inheritance from classes customMessage and baseViewController

How should I fix it ?

Upvotes: 0

Views: 2121

Answers (1)

Greg
Greg

Reputation: 25459

In swift your class can inherit just from single class. You can have a look on protocol and protocol oriented programming. The other solution is:

// Class A inherits from UIViewController
class A: UIViewController
// Class B inherits from A and also from UIViewController
class B: A

In your example you said that your main class inherits from BaseViewController which inherits from UIViewController so if you want to create another class which inherits from BaseViewController and UIViewController you just need to do:

class A: BaseViewController

that's make it inherit from UIViewController too.

Upvotes: 3

Related Questions