This repository has been archived by the owner on Jul 20, 2023. It is now read-only.
replace precondition with guard to avoid unexpected crashes #220
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I think you should consider to replace precondition with guard. There might be some cases where superview is not nil but view is not inserted in that superview which will cause a crash.
EasyTipView is a kind of tool that we give some tips for users. Generally, It doesn't matter whether the EasyTipView Message is displayed or not for application flow. Yes, that is an unexpected behaviour and should be fixed by developer, so we should warn developer with a log message, but not a crash.
It's very similar to Apple's present(_:animated:completion:)
If you try to
present
aviewController
on aviewController
which has already apresentedViewcontroller
, it doesn't crash just prints out a warning message,Warning: Attempt to present <UIAlertController: 0x147d2c6b0> on <SomeViewController: 0x147d614c0> which is already presenting.