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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
replace precondition with guard
  • Loading branch information
okankocyigit committed Oct 16, 2021

Verified

This commit was signed with the committer’s verified signature.
penelopeysm Penelope Yong
commit 6b7b24ab7c3da2217c8f649de92a513af5a45a48
10 changes: 8 additions & 2 deletions Sources/EasyTipView/EasyTipView.swift
Original file line number Diff line number Diff line change
@@ -142,11 +142,17 @@ public extension EasyTipView {
func show(animated: Bool = true, forView view: UIView, withinSuperview superview: UIView? = nil) {

#if TARGET_APP_EXTENSIONS
precondition(superview != nil, "The supplied superview parameter cannot be nil for app extensions.")
guard superview != nil else {
debugPrint("The supplied superview parameter cannot be nil for app extensions.")
return
}

let superview = superview!
#else
precondition(superview == nil || view.hasSuperview(superview!), "The supplied superview <\(superview!)> is not a direct nor an indirect superview of the supplied reference view <\(view)>. The superview passed to this method should be a direct or an indirect superview of the reference view. To display the tooltip within the main window, ignore the superview parameter.")
guard superview == nil || view.hasSuperview(superview!) else {
debugPrint("The supplied superview <\(superview!)> is not a direct nor an indirect superview of the supplied reference view <\(view)>. The superview passed to this method should be a direct or an indirect superview of the reference view. To display the tooltip within the main window, ignore the superview parameter.")
return
}

let superview = superview ?? UIApplication.shared.windows.first!
#endif