Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Types of inheritance is supported in Swift

Tags:

ios

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

like image 735
virus Avatar asked Dec 09 '14 05:12

virus


People also ask

Which inheritance is not supported in IOS Swift?

Swift doesn't allow us to declare a class with multiple base classes or superclasses, so there is no support for multiple inheritance of classes. A subclass can inherit just from one class. However, a class can conform to one or more protocols.

What are the two types of classes in inheritance in Swift?

Generally a class can inherit methods, properties and functionalities from another class. Classes can be further categorized in to sub class and super class. Swift 4 classes contain superclass which calls and access methods, properties, functions and overriding methods.

Does Swift has multiple inheritance?

Swift does not support multiple inheritance. That is, you cannot inherit from more than one class.


2 Answers

Yes in Swift and Objective-c Single and Multilevel inheritance is supported.

In swift and many other languages Multiple Inheritance is restricted by use of classes because of historical problems like deadly diamond and others ambiguities.In swift you can achieve the Multiple inheritance at some level by Protocols.

like image 93
codester Avatar answered Sep 27 '22 22:09

codester


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.

like image 40
yashwanth77 Avatar answered Sep 27 '22 22:09

yashwanth77