Search Your Question

Difference Between Inheritance And Extensions?

Ans : 

When to use extension : 
Are you adding general-purpose functionalities that should be available to every UITextField? If so, make an extension. All UITextField instances can call the new methods.

When to use inheritance : 
Are you adding functionality that should be restricted to special instances of UITextField that you would identify precisely? If so, make a subclass. Only the instances of the subclass can use the new methods.

Another diff :

In extension, there is no any specific name of extension in swift, but while subclassing there is another name of subclass.

In extension, we can not add variables (fields), in subclass it is possible to declare variables.


No comments:

Post a Comment

Thanks