Refactoring Swift UIViewPropertyAnimators out of massive view controller










0














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.










share|improve this question



















  • 2




    you can create extension for uiview, i think UIViewPropertyAnimators not the only problem. Read about MVVM
    – canister_exister
    Nov 12 '18 at 22:19






  • 2




    put your UIViewPropertyAnimators in a separate file, then make a protocol in that file and access your view property by defining a delegate of type UIViewController
    – RX9
    Nov 12 '18 at 23:08
















0














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.










share|improve this question



















  • 2




    you can create extension for uiview, i think UIViewPropertyAnimators not the only problem. Read about MVVM
    – canister_exister
    Nov 12 '18 at 22:19






  • 2




    put your UIViewPropertyAnimators in a separate file, then make a protocol in that file and access your view property by defining a delegate of type UIViewController
    – RX9
    Nov 12 '18 at 23:08














0












0








0







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.










share|improve this question















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.







swift model-view-controller refactoring uiviewpropertyanimator






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 21 '18 at 10:33

























asked Nov 12 '18 at 21:55









Super Geroy

616




616







  • 2




    you can create extension for uiview, i think UIViewPropertyAnimators not the only problem. Read about MVVM
    – canister_exister
    Nov 12 '18 at 22:19






  • 2




    put your UIViewPropertyAnimators in a separate file, then make a protocol in that file and access your view property by defining a delegate of type UIViewController
    – RX9
    Nov 12 '18 at 23:08













  • 2




    you can create extension for uiview, i think UIViewPropertyAnimators not the only problem. Read about MVVM
    – canister_exister
    Nov 12 '18 at 22:19






  • 2




    put your UIViewPropertyAnimators in a separate file, then make a protocol in that file and access your view property by defining a delegate of type UIViewController
    – RX9
    Nov 12 '18 at 23:08








2




2




you can create extension for uiview, i think UIViewPropertyAnimators not the only problem. Read about MVVM
– canister_exister
Nov 12 '18 at 22:19




you can create extension for uiview, i think UIViewPropertyAnimators not the only problem. Read about MVVM
– canister_exister
Nov 12 '18 at 22:19




2




2




put your UIViewPropertyAnimators in a separate file, then make a protocol in that file and access your view property by defining a delegate of type UIViewController
– RX9
Nov 12 '18 at 23:08





put your UIViewPropertyAnimators in a separate file, then make a protocol in that file and access your view property by defining a delegate of type UIViewController
– RX9
Nov 12 '18 at 23:08













1 Answer
1






active

oldest

votes


















1














For example:



New File named PropertyAnimators



In that file import all the libraries that you need. Then extend the original view controller like so:



extension UIViewControllerName: UIViewController, (any other delegates that you need) 
//PropertyAnimators code






share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53270678%2frefactoring-swift-uiviewpropertyanimators-out-of-massive-view-controller%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    For example:



    New File named PropertyAnimators



    In that file import all the libraries that you need. Then extend the original view controller like so:



    extension UIViewControllerName: UIViewController, (any other delegates that you need) 
    //PropertyAnimators code






    share|improve this answer

























      1














      For example:



      New File named PropertyAnimators



      In that file import all the libraries that you need. Then extend the original view controller like so:



      extension UIViewControllerName: UIViewController, (any other delegates that you need) 
      //PropertyAnimators code






      share|improve this answer























        1












        1








        1






        For example:



        New File named PropertyAnimators



        In that file import all the libraries that you need. Then extend the original view controller like so:



        extension UIViewControllerName: UIViewController, (any other delegates that you need) 
        //PropertyAnimators code






        share|improve this answer












        For example:



        New File named PropertyAnimators



        In that file import all the libraries that you need. Then extend the original view controller like so:



        extension UIViewControllerName: UIViewController, (any other delegates that you need) 
        //PropertyAnimators code







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 '18 at 5:06









        Alex Bailey

        380316




        380316



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53270678%2frefactoring-swift-uiviewpropertyanimators-out-of-massive-view-controller%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

            Museum of Modern and Contemporary Art of Trento and Rovereto