In my app there are numerous view controllers which have their own purposes. However, underneath they do share some need for common maintenance work that could use the same method code instead of each having its own copy of the code, literally pasted in.
Is there a way to share the code of these common methods ? I see two possibilities:
1) either one copy of code truly shared in memory as in a special maintenance object of methods
or
2) written once in a block of code but allocated many times as needed by each view.
Which of these is the correct path or what is the correct path, and HOW would it be implemented in the most simple manner ?
Kindness pls, new coder in the room.
Thanks.
-Ric
The best way to achieve what you want is to create a common parent class for your view controllers. So instead of inheriting directly from
UIViewController, each of your custom classes will inherit fromSomeFeatureViewController(whereSomeFeaturedescribes the common feature provided), this class inherits fromUIViewController. Now, each of your actual view controllers will inherit fromSomeFeatureViewControllerand any common methods (also any common instance variables used by these methods) can be placed in this parent class.