From da31639068ddcd82a215a32f92ee24fcee880548 Mon Sep 17 00:00:00 2001 From: Keita Watanabe Date: Mon, 5 Aug 2024 21:42:56 +0900 Subject: [PATCH] Fix existential-any for Swift6 (#639) * Fixed existential any * Added upcoming feature flag --- FloatingPanel.xcodeproj/project.pbxproj | 3 +++ Sources/Behavior.swift | 6 +++--- Sources/Controller.swift | 18 +++++++++--------- Sources/Core.swift | 8 ++++---- Sources/Layout.swift | 16 ++++++++-------- Sources/LayoutAnchoring.swift | 4 ++-- Sources/LayoutProperties.swift | 4 ++-- Sources/Position.swift | 2 +- Sources/Transitioning.swift | 16 ++++++++-------- 9 files changed, 40 insertions(+), 37 deletions(-) diff --git a/FloatingPanel.xcodeproj/project.pbxproj b/FloatingPanel.xcodeproj/project.pbxproj index 0fa506a7..bd4d2e8c 100644 --- a/FloatingPanel.xcodeproj/project.pbxproj +++ b/FloatingPanel.xcodeproj/project.pbxproj @@ -469,6 +469,7 @@ "@loader_path/Frameworks", ); MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; + OTHER_SWIFT_FLAGS = "-enable-upcoming-feature ExistentialAny"; PRODUCT_BUNDLE_IDENTIFIER = com.scenee.FloatingPanel; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -513,6 +514,7 @@ "@loader_path/Frameworks", ); MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; + OTHER_SWIFT_FLAGS = "-enable-upcoming-feature ExistentialAny"; PRODUCT_BUNDLE_IDENTIFIER = com.scenee.FloatingPanel; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -662,6 +664,7 @@ "@loader_path/Frameworks", ); MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; + OTHER_SWIFT_FLAGS = "-enable-upcoming-feature ExistentialAny"; PRODUCT_BUNDLE_IDENTIFIER = com.scenee.FloatingPanel; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; diff --git a/Sources/Behavior.swift b/Sources/Behavior.swift index 339f6395..d0716b89 100644 --- a/Sources/Behavior.swift +++ b/Sources/Behavior.swift @@ -86,9 +86,9 @@ open class FloatingPanelDefaultBehavior: FloatingPanelBehavior { class BehaviorAdapter { unowned let vc: FloatingPanelController - fileprivate var behavior: FloatingPanelBehavior + fileprivate var behavior: any FloatingPanelBehavior - init(vc: FloatingPanelController, behavior: FloatingPanelBehavior) { + init(vc: FloatingPanelController, behavior: any FloatingPanelBehavior) { self.vc = vc self.behavior = behavior } @@ -123,7 +123,7 @@ class BehaviorAdapter { } extension FloatingPanelController { - var _behavior: FloatingPanelBehavior { + var _behavior: any FloatingPanelBehavior { get { floatingPanel.behaviorAdapter.behavior } set { floatingPanel.behaviorAdapter.behavior = newValue} } diff --git a/Sources/Controller.swift b/Sources/Controller.swift index f01a1ea0..fdcf96c6 100644 --- a/Sources/Controller.swift +++ b/Sources/Controller.swift @@ -10,11 +10,11 @@ import os.log @objc public protocol FloatingPanelControllerDelegate { /// Returns a FloatingPanelLayout object. If you use the default one, you can use a `FloatingPanelBottomLayout` object. @objc(floatingPanel:layoutForTraitCollection:) optional - func floatingPanel(_ fpc: FloatingPanelController, layoutFor newCollection: UITraitCollection) -> FloatingPanelLayout + func floatingPanel(_ fpc: FloatingPanelController, layoutFor newCollection: UITraitCollection) -> any FloatingPanelLayout /// Returns a FloatingPanelLayout object. If you use the default one, you can use a `FloatingPanelBottomLayout` object. @objc(floatingPanel:layoutForSize:) optional - func floatingPanel(_ fpc: FloatingPanelController, layoutFor size: CGSize) -> FloatingPanelLayout + func floatingPanel(_ fpc: FloatingPanelController, layoutFor size: CGSize) -> any FloatingPanelLayout /// Returns a UIViewPropertyAnimator object to add/present the panel to a position. /// @@ -151,7 +151,7 @@ open class FloatingPanelController: UIViewController { /// The delegate of a panel controller object. @objc - public weak var delegate: FloatingPanelControllerDelegate?{ + public weak var delegate: (any FloatingPanelControllerDelegate)?{ didSet{ didUpdateDelegate() } @@ -199,7 +199,7 @@ open class FloatingPanelController: UIViewController { /// You need to call ``invalidateLayout()`` if you want to apply a new layout object into the panel /// immediately. @objc - public var layout: FloatingPanelLayout { + public var layout: any FloatingPanelLayout { get { _layout } set { _layout = newValue @@ -212,7 +212,7 @@ open class FloatingPanelController: UIViewController { /// The behavior object that the controller manages @objc - public var behavior: FloatingPanelBehavior { + public var behavior: any FloatingPanelBehavior { get { _behavior } set { _behavior = newValue @@ -283,7 +283,7 @@ open class FloatingPanelController: UIViewController { /// Initialize a newly created panel controller. @objc - public init(delegate: FloatingPanelControllerDelegate? = nil) { + public init(delegate: (any FloatingPanelControllerDelegate)? = nil) { super.init(nibName: nil, bundle: nil) self.delegate = delegate setUp() @@ -295,7 +295,7 @@ open class FloatingPanelController: UIViewController { modalPresentationStyle = .custom transitioningDelegate = modalTransition - let initialLayout: FloatingPanelLayout + let initialLayout: any FloatingPanelLayout if let layout = delegate?.floatingPanel?(self, layoutFor: traitCollection) { initialLayout = layout } else { @@ -345,7 +345,7 @@ open class FloatingPanelController: UIViewController { floatingPanel.adjustScrollContentInsetIfNeeded() } - open override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { + open override func viewWillTransition(to size: CGSize, with coordinator: any UIViewControllerTransitionCoordinator) { super.viewWillTransition(to: size, with: coordinator) if self.view.bounds.size == size { @@ -364,7 +364,7 @@ open class FloatingPanelController: UIViewController { } } - open override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) { + open override func willTransition(to newCollection: UITraitCollection, with coordinator: any UIViewControllerTransitionCoordinator) { super.willTransition(to: newCollection, with: coordinator) if shouldUpdateLayout(from: traitCollection, to: newCollection) == false { diff --git a/Sources/Core.swift b/Sources/Core.swift index 45c9c817..1d4cde1d 100644 --- a/Sources/Core.swift +++ b/Sources/Core.swift @@ -78,7 +78,7 @@ class Core: NSObject, UIGestureRecognizerDelegate { // MARK: - Interface - init(_ vc: FloatingPanelController, layout: FloatingPanelLayout, behavior: FloatingPanelBehavior) { + init(_ vc: FloatingPanelController, layout: any FloatingPanelLayout, behavior: any FloatingPanelBehavior) { ownerVC = vc surfaceView = SurfaceView() @@ -1245,7 +1245,7 @@ public final class FloatingPanelPanGestureRecognizer: UIPanGestureRecognizer { /// /// - Note: The delegate is used by FloatingPanel itself. If you set your own delegate object, an /// exception is raised. If you want to handle the methods of UIGestureRecognizerDelegate, you can use `delegateProxy`. - public override weak var delegate: UIGestureRecognizerDelegate? { + public override weak var delegate: (any UIGestureRecognizerDelegate)? { get { return super.delegate } @@ -1266,7 +1266,7 @@ public final class FloatingPanelPanGestureRecognizer: UIPanGestureRecognizer { /// The default object implementing a set methods of the delegate of the gesture recognizer. /// /// Use this property with ``delegateProxy`` when you need to use the default gesture behaviors in a proxy implementation. - public var delegateOrigin: UIGestureRecognizerDelegate { + public var delegateOrigin: any UIGestureRecognizerDelegate { return floatingPanel } @@ -1274,7 +1274,7 @@ public final class FloatingPanelPanGestureRecognizer: UIPanGestureRecognizer { /// /// `UIGestureRecognizerDelegate` methods implementing by this object are called instead of the default delegate, /// ``delegateOrigin``. - public weak var delegateProxy: UIGestureRecognizerDelegate? { + public weak var delegateProxy: (any UIGestureRecognizerDelegate)? { didSet { self.delegate = floatingPanel?.panGestureDelegateRouter // Update the cached IMP } diff --git a/Sources/Layout.swift b/Sources/Layout.swift index 579a1416..38eff34d 100644 --- a/Sources/Layout.swift +++ b/Sources/Layout.swift @@ -13,7 +13,7 @@ import os.log @objc var initialState: FloatingPanelState { get } /// Returns the layout anchors to specify the snapping locations for each state. - @objc var anchors: [FloatingPanelState: FloatingPanelLayoutAnchoring] { get } + @objc var anchors: [FloatingPanelState: any FloatingPanelLayoutAnchoring] { get } /// Returns layout constraints to determine the cross dimension of a panel. @objc optional func prepareLayout(surfaceView: UIView, in view: UIView) -> [NSLayoutConstraint] @@ -32,7 +32,7 @@ open class FloatingPanelBottomLayout: NSObject, FloatingPanelLayout { return .half } - open var anchors: [FloatingPanelState: FloatingPanelLayoutAnchoring] { + open var anchors: [FloatingPanelState: any FloatingPanelLayoutAnchoring] { return [ .full: FloatingPanelLayoutAnchor(absoluteInset: 18.0, edge: .top, referenceGuide: .safeArea), .half: FloatingPanelLayoutAnchor(fractionalInset: 0.5, edge: .bottom, referenceGuide: .safeArea), @@ -66,7 +66,7 @@ class LayoutAdapter { private unowned var vc: FloatingPanelController private let defaultLayout = FloatingPanelBottomLayout() - fileprivate var layout: FloatingPanelLayout { + fileprivate var layout: any FloatingPanelLayout { didSet { surfaceView.position = position } @@ -289,7 +289,7 @@ class LayoutAdapter { return offset.rounded(by: surfaceView.fp_displayScale) } - private var hiddenAnchor: FloatingPanelLayoutAnchoring { + private var hiddenAnchor: any FloatingPanelLayoutAnchoring { switch position { case .top: return FloatingPanelLayoutAnchor(absoluteInset: -100, edge: .top, referenceGuide: .superview) @@ -302,7 +302,7 @@ class LayoutAdapter { } } - init(vc: FloatingPanelController, layout: FloatingPanelLayout) { + init(vc: FloatingPanelController, layout: any FloatingPanelLayout) { self.vc = vc self.layout = layout } @@ -406,7 +406,7 @@ class LayoutAdapter { } } - private func referenceEdge(of anchor: FloatingPanelLayoutAnchoring) -> FloatingPanelReferenceEdge { + private func referenceEdge(of anchor: any FloatingPanelLayoutAnchoring) -> FloatingPanelReferenceEdge { switch anchor { case is FloatingPanelIntrinsicLayoutAnchor, is FloatingPanelAdaptiveLayoutAnchor: @@ -548,7 +548,7 @@ class LayoutAdapter { NSLayoutConstraint.deactivate(constraint: interactionConstraint) interactionConstraint = nil - let layoutGuideProvider: LayoutGuideProvider + let layoutGuideProvider: any LayoutGuideProvider switch anchor.referenceGuide { case .safeArea: layoutGuideProvider = vc.view.safeAreaLayoutGuide @@ -856,7 +856,7 @@ extension LayoutAdapter { } extension FloatingPanelController { - var _layout: FloatingPanelLayout { + var _layout: any FloatingPanelLayout { get { floatingPanel.layoutAdapter.layout } diff --git a/Sources/LayoutAnchoring.swift b/Sources/LayoutAnchoring.swift index 492ae2e5..a3710db8 100644 --- a/Sources/LayoutAnchoring.swift +++ b/Sources/LayoutAnchoring.swift @@ -66,7 +66,7 @@ public extension FloatingPanelLayoutAnchor { } } - private func layoutConstraints(_ layoutGuide: LayoutGuideProvider, for edgeAnchor: NSLayoutYAxisAnchor) -> [NSLayoutConstraint] { + private func layoutConstraints(_ layoutGuide: any LayoutGuideProvider, for edgeAnchor: NSLayoutYAxisAnchor) -> [NSLayoutConstraint] { switch referenceEdge { case .top: if isAbsolute { @@ -85,7 +85,7 @@ public extension FloatingPanelLayoutAnchor { } } - private func layoutConstraints(_ layoutGuide: LayoutGuideProvider, for edgeAnchor: NSLayoutXAxisAnchor) -> [NSLayoutConstraint] { + private func layoutConstraints(_ layoutGuide: any LayoutGuideProvider, for edgeAnchor: NSLayoutXAxisAnchor) -> [NSLayoutConstraint] { switch referenceEdge { case .left: if isAbsolute { diff --git a/Sources/LayoutProperties.swift b/Sources/LayoutProperties.swift index 6eeb5911..f2f95fff 100644 --- a/Sources/LayoutProperties.swift +++ b/Sources/LayoutProperties.swift @@ -36,7 +36,7 @@ extension FloatingPanelReferenceEdge { } extension FloatingPanelLayoutReferenceGuide { - func layoutGuide(vc: UIViewController) -> LayoutGuideProvider { + func layoutGuide(vc: UIViewController) -> any LayoutGuideProvider { switch self { case .safeArea: return vc.view.safeAreaLayoutGuide @@ -55,7 +55,7 @@ extension FloatingPanelLayoutReferenceGuide { } extension FloatingPanelLayoutContentBoundingGuide { - func layoutGuide(_ fpc: FloatingPanelController) -> LayoutGuideProvider? { + func layoutGuide(_ fpc: FloatingPanelController) -> (any LayoutGuideProvider)? { switch self { case .superview: return fpc.view diff --git a/Sources/Position.swift b/Sources/Position.swift index ebf84f0d..2c7c1317 100644 --- a/Sources/Position.swift +++ b/Sources/Position.swift @@ -26,7 +26,7 @@ extension FloatingPanelPosition { } } - func mainDimensionAnchor(_ layoutGuide: LayoutGuideProvider) -> NSLayoutDimension { + func mainDimensionAnchor(_ layoutGuide: any LayoutGuideProvider) -> NSLayoutDimension { switch self { case .top, .bottom: return layoutGuide.heightAnchor case .left, .right: return layoutGuide.widthAnchor diff --git a/Sources/Transitioning.swift b/Sources/Transitioning.swift index 88ab2348..d83d77ae 100644 --- a/Sources/Transitioning.swift +++ b/Sources/Transitioning.swift @@ -5,11 +5,11 @@ import UIKit class ModalTransition: NSObject, UIViewControllerTransitioningDelegate { func animationController(forPresented presented: UIViewController, presenting: UIViewController, - source: UIViewController) -> UIViewControllerAnimatedTransitioning? { + source: UIViewController) -> (any UIViewControllerAnimatedTransitioning)? { return ModalPresentTransition() } - func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { + func animationController(forDismissed dismissed: UIViewController) -> (any UIViewControllerAnimatedTransitioning)? { return ModalDismissTransition() } @@ -81,7 +81,7 @@ class PresentationController: UIPresentationController { } class ModalPresentTransition: NSObject, UIViewControllerAnimatedTransitioning { - func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval { + func transitionDuration(using transitionContext: (any UIViewControllerContextTransitioning)?) -> TimeInterval { guard let fpc = transitionContext?.viewController(forKey: .to) as? FloatingPanelController else { fatalError()} @@ -90,7 +90,7 @@ class ModalPresentTransition: NSObject, UIViewControllerAnimatedTransitioning { return TimeInterval(animator.duration) } - func interruptibleAnimator(using transitionContext: UIViewControllerContextTransitioning) -> UIViewImplicitlyAnimating { + func interruptibleAnimator(using transitionContext: any UIViewControllerContextTransitioning) -> any UIViewImplicitlyAnimating { guard let fpc = transitionContext.viewController(forKey: .to) as? FloatingPanelController else { fatalError() } @@ -110,13 +110,13 @@ class ModalPresentTransition: NSObject, UIViewControllerAnimatedTransitioning { return transitionAnimator } - func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { + func animateTransition(using transitionContext: any UIViewControllerContextTransitioning) { self.interruptibleAnimator(using: transitionContext).startAnimation() } } class ModalDismissTransition: NSObject, UIViewControllerAnimatedTransitioning { - func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval { + func transitionDuration(using transitionContext: (any UIViewControllerContextTransitioning)?) -> TimeInterval { guard let fpc = transitionContext?.viewController(forKey: .from) as? FloatingPanelController else { fatalError()} @@ -125,7 +125,7 @@ class ModalDismissTransition: NSObject, UIViewControllerAnimatedTransitioning { return TimeInterval(animator.duration) } - func interruptibleAnimator(using transitionContext: UIViewControllerContextTransitioning) -> UIViewImplicitlyAnimating { + func interruptibleAnimator(using transitionContext: any UIViewControllerContextTransitioning) -> any UIViewImplicitlyAnimating { guard let fpc = transitionContext.viewController(forKey: .from) as? FloatingPanelController else { fatalError() } @@ -142,7 +142,7 @@ class ModalDismissTransition: NSObject, UIViewControllerAnimatedTransitioning { return fpc.transitionAnimator! } - func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { + func animateTransition(using transitionContext: any UIViewControllerContextTransitioning) { self.interruptibleAnimator(using: transitionContext).startAnimation() } }