From 6b7b24ab7c3da2217c8f649de92a513af5a45a48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Okan=20Koc=CC=A7yig=CC=86it?= Date: Sat, 16 Oct 2021 10:13:59 +0300 Subject: [PATCH] replace precondition with guard --- Sources/EasyTipView/EasyTipView.swift | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Sources/EasyTipView/EasyTipView.swift b/Sources/EasyTipView/EasyTipView.swift index 3d3e1bed..0b77944c 100644 --- a/Sources/EasyTipView/EasyTipView.swift +++ b/Sources/EasyTipView/EasyTipView.swift @@ -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