-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(#717) Fix issue with deallocating view controller when replacing root view controller of UIWindow #718
Conversation
…n replacing root view controller of UIWindow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code loos good, though reviewing this I wonder if this should call the completion with an error or throw on error at least.
This method currently just consumes errors quietly. Suprised no one has complained about this.
@JoeMatt agree there should be some error handling. Do you think about: |
Would you mind if I suggest one more variant? public enum ReplaceRootViewError: Error { // smth like that not sure about naming
... // describe all your failure cases
}
public enum Status {
case success
case failure(ReplaceRootViewError) // or its can be just Error
}
func replaceViewController(with next: UIViewController, completion: ((status: Status) -> Void)? = nil) {
...
// failure
completion?(.failure(ReplaceRootViewError.someError))
...
// success
completion?(.success)
...
} It would be Ideal to throw error as @JoeMatt said, to identify what was wrong. Also the last case with window should also call completion when transition finished (now its not). Hope, it was helpful :) |
This looks really helpful indeed, I'll take a look at incorporating as soon as I have the bandwidth or if someone else opens/updates a PR for review. Thanks @dimatarelkin |
@dimatarelkin, if you're thinking of using an enum to model the completion status, why not use Swift's Result? public enum ReplaceRootViewError: Error {
...
}
typealias CompletionResult = Result<Void, ReplaceRootViewError> // Could also use a plain Error here
func replaceViewController(with next: UIViewController, completion: ((result: CompletionResult) -> Void)? = nil) {
...
// failure
completion?(.failure(.someError))
...
// success
completion?(.success(()))
...
} |
Yeah, that would be nice, thanks @oconnelltoby |
Fix issue from ticket: #717