'Types of inheritance is supported in Swift

i guess only these two types are available in swift, i just want to know, am i missing any, your help will be appreciated?

  • Single

  • Multilevel



Solution 1:[1]

Only those two are avaliable in swift but you can implement multiple inheritance.You could use a protocol to achieve the same result as Multiple inheritance.

Solution 2:[2]

iOS supported Inheritance types.

  1. Single
  2. Multilevel
  3. Hierarchical
  4. Hybrid (combination of more than one form of inheritance)

Note: Multiple Inheritance not supported by many modern languages, due to avoid Diamond shape ambiguity.

Yes, both languages (Swift and Objective-C) support hierarchical inheritance. There are countless examples in the iOS SDK.

UIResponder is subclassed by UIApplication, UIView, UIViewController.

UIView obviously has many subclasses as does UIViewController.

And Hybrid also, here is a sample, combination of Multilevel and Hierarchical.

class Parent {
    fun_f1
}

class Child1: Parent {
    fun_f2
}

class Child2: Parent {
    fun_f3
}

class Child3: Child1 {
    fun_f4
}

class TestHybrid { 
    fun test() { 
        var c3: Child3  
        c3.f1();  
        c3.f2();   
        c3.f4();    
    } 
} 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 yashwanth77
Solution 2 ouflak