Skip to content
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

Merged
merged 1 commit into from
May 6, 2022

Conversation

rafalwojcik
Copy link
Contributor

Fix issue from ticket: #717

…n replacing root view controller of UIWindow
Copy link
Collaborator

@JoeMatt JoeMatt left a 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 JoeMatt self-assigned this Apr 16, 2021
@rafalwojcik
Copy link
Contributor Author

rafalwojcik commented Apr 19, 2021

@JoeMatt agree there should be some error handling.

Do you think about: completion: ((success: Bool) -> Void)? = nil or completion: ((Error?) -> Void)? = nil?

@JoeMatt JoeMatt added this to the 1.7.0 milestone Apr 23, 2021
@dimatarelkin
Copy link

completion: ((success: Bool) -> Void)? = nil

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.
You need only give descriptive names to these errors (the hardest part 🥲)

Also the last case with window should also call completion when transition finished (now its not).
And fix cases that just make return and telling nothing to function caller about completion (so caller that waits for completion never find out that function completed).

Hope, it was helpful :)

@JoeMatt
Copy link
Collaborator

JoeMatt commented Sep 9, 2021

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

@oconnelltoby
Copy link

oconnelltoby commented Sep 23, 2021

@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(()))
  ...
}

@dimatarelkin
Copy link

@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

@kuyazee kuyazee merged commit 9f8fe2b into HeroTransitions:develop May 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants