I have a view controller which has 5 different subviews, these subviews are changed according to some conditions, then there are functions which apply background color and add some minor aesthetics to the views.

I have segregated the functions in the viewcontroller only for views i.e Applying colors,adding views and button touch events etc.

Only for controllers ViewDidLoad, ViewDidAppear etc.

Rest I call it as model, as it does some calculations and other stuff. Calculating the constraints and constants for the view. Can anyone suggest me anyway how to incorporate the view, controller and model functions in separate class? I don't like everything crowding up in the same viewcontroller.

  • 3
    You should read this article. Among other things, it discusses the "massive view controller" specifically. Commented Sep 7, 2016 at 15:05
  • 1
    This topic can easily fill an entire book. In fact, at least one has been written. You should pick up a copy of "Working Effectively with Legacy Code".
    – RubberDuck
    Commented Nov 6, 2016 at 10:10

3 Answers 3


I suggest you add ViewModels.

For example say you have 'when Model.State = cancelled then colour is red'

Create a ViewModel with property Colour and a constructor which takes the Model as an argument and calculates and sets the colour.

Pass this ViewModel to the view rather than the model.


Based on the the current state, one simple yet organized solution would be to create something like a "[YourViewController]Views" directory.

In this directory create separate class files for each subview and migrate their respective related code from your view controller file. You can make each one a subclass of UIView.


Based on your issue you can also try to extend your view file to minor sub view modules and trigger them when the model changes.

Not the answer you're looking for? Browse other questions tagged or ask your own question.