Deciding which type you should use
Choosing the wrong type of object to use in your application can have bad implications for your app on several levels. For instance, your app could suffer from unwanted side-effects when a reference type is modified in some unexpected place. Or you could end up with a lot of duplicated logic if you use a struct instead of a class in certain places. Your app could even suffer in terms of performance when you choose a slow reference type where a value type would have been a better choice. You should always evaluate what type of object is best-suited for your current use case to make sure your code strikes a balanced trade-off between maintainability and performance.
When to use a reference type?
A great time to use a reference type is when you are subclassing a built-in class, such as UIViewController
. In these cases, there is no point in fighting the system because that would definitely do more harm than good. Another time to use a reference type is when you...