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
10 changes: 8 additions & 2 deletions Sources/EasyTipView/EasyTipView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down