From b0fb9e7eedc849d971050b177c7020be8926004c Mon Sep 17 00:00:00 2001 From: Giulio Date: Fri, 17 May 2019 18:42:21 +0200 Subject: [PATCH] Improve Swift syntax (#25) * Replace init-ializable struct with enums * Add AnyObject requirement to protocols * Hide init?(coder aDecoder: NSCoder) func * Improve Swift syntax * Revert "Replace init-ializable struct with enums" This reverts commit 1be2e8c23cfc75959d7fd1c90028d1a7a257b7d1. --- PanModal/Presentable/PanModalPresentable.swift | 2 +- PanModal/Presenter/PanModalPresenter.swift | 2 +- PanModal/View/PanContainerView.swift | 7 +++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/PanModal/Presentable/PanModalPresentable.swift b/PanModal/Presentable/PanModalPresentable.swift index 7520a95..70f2246 100644 --- a/PanModal/Presentable/PanModalPresentable.swift +++ b/PanModal/Presentable/PanModalPresentable.swift @@ -18,7 +18,7 @@ import UIKit } ``` */ -public protocol PanModalPresentable { +public protocol PanModalPresentable: AnyObject { /** The scroll view embedded in the view controller. diff --git a/PanModal/Presenter/PanModalPresenter.swift b/PanModal/Presenter/PanModalPresenter.swift index a90d8bb..9cbd876 100644 --- a/PanModal/Presenter/PanModalPresenter.swift +++ b/PanModal/Presenter/PanModalPresenter.swift @@ -17,7 +17,7 @@ import UIKit sourceRect: .zero) ``` */ -protocol PanModalPresenter { +protocol PanModalPresenter: AnyObject { /** A flag that returns true if the current presented view controller diff --git a/PanModal/View/PanContainerView.swift b/PanModal/View/PanContainerView.swift index 11f3ef8..a52d814 100644 --- a/PanModal/View/PanContainerView.swift +++ b/PanModal/View/PanContainerView.swift @@ -20,8 +20,9 @@ class PanContainerView: UIView { addSubview(presentedView) } + @available(*, unavailable) required init?(coder aDecoder: NSCoder) { - fatalError() + fatalError("init(coder:) has not been implemented") } } @@ -33,7 +34,9 @@ extension UIView { from the view hierachy */ var panContainerView: PanContainerView? { - return subviews.compactMap({ $0 as? PanContainerView }).first + return subviews.first(where: { view -> Bool in + view is PanContainerView + }) as? PanContainerView } }