I am trying to refactor my Swift massive view controller which now has >900 lines (too many).
How can I separate the creation of my UIViewPropertyAnimators
(~100 lines) from my main UIViewController
?
The thing is that the UIViewPropertyAnimators
need reference to the view
property and the UIViews
they are animating. Do I create a struct
with a weak var
to which I assign the view
reference by dependency injection? I would also need to refer to the UIView
objects somehow.
Not sure what is the best way to refactor this without creating a kind of circularity. Any ideas?
Addition:
As all animators only related to part of the window I have now created a child view controller and moved the animators there. I think this is also a viable solution. I had to add delegate pattern. At the end, the parent view controller is ~100 lines shorter and I have 'separated concern' as they say.
For example:
New File named PropertyAnimators
In that file import all the libraries that you need. Then extend the original view controller like so: