Your Swift Classes Should Be Final
I’ve previously written about favouring composition over inheritance when coding in Swift.
I can even pull in my own definition of inheritance here:
Inheritance: A fundamental OO concept that enables new objects to take on the properties of existing objects. A class that inherits from a superclass is called a subclass or derived class.
So generally we don’t favour using inheritance when coding in Swift.
So what is the issue?
If you’re using a base class in Swift, you’re doing it wrong
Cut out repeated code from your view controllers
I remember that article! The basic point of that article was we should be implementing the SOLID principles while coding in Swift.
When we’re working in a team though, you can’t guarantee that your colleagues are going to follow all of that goodness.
So my minimum
UIViewController might look something like the following
and yes, it really is my habit to programmatically instantiate a
UIViewController with a
nib like that.
What if you use the
Storyboard? Your most basic
UIViewController might look more like the following: