-
Notifications
You must be signed in to change notification settings - Fork 594
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
Fix force unwrap in BaseCollectionViewController #538
Fix force unwrap in BaseCollectionViewController #538
Conversation
Codecov Report
@@ Coverage Diff @@
## master #538 +/- ##
==========================================
+ Coverage 62.94% 62.95% +0.01%
==========================================
Files 77 77
Lines 4037 4063 +26
==========================================
+ Hits 2541 2558 +17
- Misses 1496 1505 +9
Continue to review full report at Codecov.
|
@alaija Thank you for your contribution! It makes sense to use optional values for views in view controllers. View hierarchy may not be initialized when some view controller functions are called. However, a view controller contains many functions that are using views and expecting a view hierarchy to be initialized when they are called, for example, So, a question should be asked: "Does it make sense to call a function that is using views when view hierarchy is not initialized?" If the answer is "No", then Currently, all views in So, let's take a look at some examples: So, my proposal is to add Using optional values for views is a safer way, but it should be applied to all views at the same time for consistency. This would be a huge refactoring. Also, it will make access to a view hierarchy less convenient. I would say, that every function that is using a view defined as an optional type will need to add a guard statement to unwrap it. There should be a balance between convenience and safety. I didn't find it yet :) What do you think? |
Actually, we made this(isViewLoaded) workaround in our child viewcontroller, but it looks like workaround and not a solution, cause we speak about “Base” class and someone who will implement his child viewcontroller can be faced to the problem again. Anyway layouting is just one case, there are too many of them, and I really surprised that no one met any before me, so in my opinion optional views is the only solution. |
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.
Everything looks good. I left few comments. Can you take a look?
Chatto/Source/ChatController/BaseChatViewController+Scrolling.swift
Outdated
Show resolved
Hide resolved
Chatto/Source/ChatController/BaseChatViewController+Scrolling.swift
Outdated
Show resolved
Hide resolved
@@ -128,7 +130,10 @@ extension BaseChatViewController { | |||
changes: CollectionChanges, | |||
updateType: UpdateType, | |||
completion: @escaping () -> Void) { | |||
|
|||
guard let collectionView = self.collectionView else { |
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.
Please check this method carefully, cause it too complicated to get what blocks should I call on exit.
P.S. It is a good candidate for refactoring
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.
There are many places that requires refactoring :) Someday we will take care about them
Force unwrap leads to crash in cases when ViewController addresses to collectionview before it was loaded. e.g. You can try to rotate device when chat is initialized inside unopened tab inside UITabBarController.