Refactoring Swift UIViewPropertyAnimators out of massive view controller
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
add a comment |
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
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 yourUIViewPropertyAnimators
in a separate file, then make a protocol in that file and access yourview
property by defining adelegate
of typeUIViewController
– RX9
Nov 12 '18 at 23:08
add a comment |
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
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
swift model-view-controller refactoring uiviewpropertyanimator
edited Dec 21 '18 at 10:33
Super Geroy
asked Nov 12 '18 at 21:55
Super GeroySuper 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 yourUIViewPropertyAnimators
in a separate file, then make a protocol in that file and access yourview
property by defining adelegate
of typeUIViewController
– RX9
Nov 12 '18 at 23:08
add a comment |
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 yourUIViewPropertyAnimators
in a separate file, then make a protocol in that file and access yourview
property by defining adelegate
of typeUIViewController
– 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
add a comment |
1 Answer
1
active
oldest
votes
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
}
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
}
add a comment |
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
}
add a comment |
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
}
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
}
answered Nov 13 '18 at 5:06
Alex BaileyAlex Bailey
392316
392316
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 yourview
property by defining adelegate
of typeUIViewController
– RX9
Nov 12 '18 at 23:08