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

Safely unwrap selectedViewController before calling the delegate methods #230

Merged
merged 2 commits into from
Aug 15, 2018

Conversation

ChrisDunaetz
Copy link

Fix for: #225

Ideally, scrollViewDidScroll(_:) probably just shouldn't be called if selectedViewController` is nil. But since that code is from another, less maintained repo, this is a quick fix to prevent force-unwrapping crashes.

if let selectedViewController = selectedViewController,
self.navigationDirection == .reverse { // check if direction changed
self.didFinishScrolling(to: selectedViewController)
self.willScroll(from: selectedViewController, to: self.afterViewController!)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should afterViewController and beforeViewController also be safely unwrapped?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that, but then there are about 40 instances of force unwrapping in this file and I figured it would be smarter to only if I only changed what's needed instead of fixing everything and potentially breaking something accidentally.

@rechsteiner
Copy link
Owner

Thank you so much for doing this – I really appreciate it 🙌

@rechsteiner rechsteiner merged commit fefcd24 into rechsteiner:master Aug 15, 2018
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.

3 participants