From 4b03b8ec0f13cf9273fe1596f0f371d07fd25dc7 Mon Sep 17 00:00:00 2001 From: Alex K Date: Fri, 21 Sep 2018 09:41:36 +0300 Subject: [PATCH] converting to swift 4.2 Fixes #85 --- .../project.pbxproj | 16 ++++++---------- .../DemoExpandingCollection/AppDelegate.swift | 6 +++--- .../DemoTableViewController.swift | 4 ++-- .../DemoViewController/DemoViewController.swift | 2 +- .../AnimatingBarButton/AnimationBarButton.swift | 2 +- .../Animations/Rotatable.swift | 2 +- .../Cells/BasePageCollectionCell.swift | 10 +++++----- .../Layout/PageCollectionLayout.swift | 4 ++-- .../CollectionView/PageCollectionView.swift | 4 ++-- .../CornerAnimatable/CornerAnimatable.swift | 2 +- .../Constraints Helpers/ConstraintsHelper.swift | 10 +++++----- Source/TransitionDriver/TransitionDriver.swift | 10 +++++----- expanding-collection.podspec | 2 +- 13 files changed, 35 insertions(+), 39 deletions(-) diff --git a/DemoExpandingCollection/DemoExpandingCollection.xcodeproj/project.pbxproj b/DemoExpandingCollection/DemoExpandingCollection.xcodeproj/project.pbxproj index 3cf2e6e..8316372 100644 --- a/DemoExpandingCollection/DemoExpandingCollection.xcodeproj/project.pbxproj +++ b/DemoExpandingCollection/DemoExpandingCollection.xcodeproj/project.pbxproj @@ -446,12 +446,12 @@ 848596271CF585F3000BCC74 = { CreatedOnToolsVersion = 7.3.1; DevelopmentTeam = 34MUF9YXTA; - LastSwiftMigration = 0920; + LastSwiftMigration = 1000; }; 8499D8131D001B82004B5B37 = { CreatedOnToolsVersion = 7.3.1; DevelopmentTeam = LEAZS7L33U; - LastSwiftMigration = 0920; + LastSwiftMigration = 1000; }; }; }; @@ -689,8 +689,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.ramotion.dev1; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; - SWIFT_SWIFT3_OBJC_INFERENCE = Off; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -708,8 +707,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.ramotion.dev1; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; - SWIFT_SWIFT3_OBJC_INFERENCE = Off; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Release; }; @@ -730,8 +728,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.ramotion.dev; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_SWIFT3_OBJC_INFERENCE = Off; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -755,8 +752,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.ramotion.dev; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_SWIFT3_OBJC_INFERENCE = Off; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; diff --git a/DemoExpandingCollection/DemoExpandingCollection/AppDelegate.swift b/DemoExpandingCollection/DemoExpandingCollection/AppDelegate.swift index 234dca1..a2d9329 100644 --- a/DemoExpandingCollection/DemoExpandingCollection/AppDelegate.swift +++ b/DemoExpandingCollection/DemoExpandingCollection/AppDelegate.swift @@ -13,7 +13,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { configureNavigationTabBar() return true } @@ -32,8 +32,8 @@ extension AppDelegate { shadow.shadowColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.1) UINavigationBar.appearance().titleTextAttributes = [ - NSAttributedStringKey.foregroundColor: UIColor.white, - NSAttributedStringKey.shadow: shadow, + NSAttributedString.Key.foregroundColor: UIColor.white, + NSAttributedString.Key.shadow: shadow, ] } } diff --git a/DemoExpandingCollection/DemoExpandingCollection/ViewControllers/DemoTableViewController/DemoTableViewController.swift b/DemoExpandingCollection/DemoExpandingCollection/ViewControllers/DemoTableViewController/DemoTableViewController.swift index 9862ea6..e70628c 100644 --- a/DemoExpandingCollection/DemoExpandingCollection/ViewControllers/DemoTableViewController/DemoTableViewController.swift +++ b/DemoExpandingCollection/DemoExpandingCollection/ViewControllers/DemoTableViewController/DemoTableViewController.swift @@ -27,8 +27,8 @@ class DemoTableViewController: ExpandingTableViewController { extension DemoTableViewController { fileprivate func configureNavBar() { - navigationItem.leftBarButtonItem?.image = navigationItem.leftBarButtonItem?.image!.withRenderingMode(UIImageRenderingMode.alwaysOriginal) - navigationItem.rightBarButtonItem?.image = navigationItem.rightBarButtonItem?.image!.withRenderingMode(UIImageRenderingMode.alwaysOriginal) + navigationItem.leftBarButtonItem?.image = navigationItem.leftBarButtonItem?.image!.withRenderingMode(UIImage.RenderingMode.alwaysOriginal) + navigationItem.rightBarButtonItem?.image = navigationItem.rightBarButtonItem?.image!.withRenderingMode(UIImage.RenderingMode.alwaysOriginal) } } diff --git a/DemoExpandingCollection/DemoExpandingCollection/ViewControllers/DemoViewController/DemoViewController.swift b/DemoExpandingCollection/DemoExpandingCollection/ViewControllers/DemoViewController/DemoViewController.swift index 85309bb..8d8991f 100644 --- a/DemoExpandingCollection/DemoExpandingCollection/ViewControllers/DemoViewController/DemoViewController.swift +++ b/DemoExpandingCollection/DemoExpandingCollection/ViewControllers/DemoViewController/DemoViewController.swift @@ -53,7 +53,7 @@ extension DemoViewController { } fileprivate func configureNavBar() { - navigationItem.leftBarButtonItem?.image = navigationItem.leftBarButtonItem?.image!.withRenderingMode(UIImageRenderingMode.alwaysOriginal) + navigationItem.leftBarButtonItem?.image = navigationItem.leftBarButtonItem?.image!.withRenderingMode(UIImage.RenderingMode.alwaysOriginal) } } diff --git a/DemoExpandingCollection/DemoExpandingCollection/Views/AnimatingBarButton/AnimationBarButton.swift b/DemoExpandingCollection/DemoExpandingCollection/Views/AnimatingBarButton/AnimationBarButton.swift index d6129b9..0370cfa 100644 --- a/DemoExpandingCollection/DemoExpandingCollection/Views/AnimatingBarButton/AnimationBarButton.swift +++ b/DemoExpandingCollection/DemoExpandingCollection/Views/AnimatingBarButton/AnimationBarButton.swift @@ -66,7 +66,7 @@ extension AnimatingBarButton { fileprivate func configureImageView(_ imageView: UIImageView, imageName: String) { guard let customView = customView else { return } - guard let image = UIImage(named: imageName)?.withRenderingMode(UIImageRenderingMode.alwaysTemplate) else { return } + guard let image = UIImage(named: imageName)?.withRenderingMode(UIImage.RenderingMode.alwaysTemplate) else { return } imageView.image = image imageView.contentMode = .scaleAspectFit diff --git a/DemoExpandingCollection/DemoExpandingCollection/Views/AnimatingBarButton/Animations/Rotatable.swift b/DemoExpandingCollection/DemoExpandingCollection/Views/AnimatingBarButton/Animations/Rotatable.swift index 3f15e99..cdff634 100644 --- a/DemoExpandingCollection/DemoExpandingCollection/Views/AnimatingBarButton/Animations/Rotatable.swift +++ b/DemoExpandingCollection/DemoExpandingCollection/Views/AnimatingBarButton/Animations/Rotatable.swift @@ -35,7 +35,7 @@ extension Rotatable { $0.duration = duration $0.fromValue = from $0.toValue = to - $0.fillMode = kCAFillModeForwards + $0.fillMode = CAMediaTimingFillMode.forwards $0.isRemovedOnCompletion = false } } diff --git a/Source/ExpandingViewController/CollectionView/Cells/BasePageCollectionCell.swift b/Source/ExpandingViewController/CollectionView/Cells/BasePageCollectionCell.swift index 9641215..0f08fe1 100644 --- a/Source/ExpandingViewController/CollectionView/Cells/BasePageCollectionCell.swift +++ b/Source/ExpandingViewController/CollectionView/Cells/BasePageCollectionCell.swift @@ -135,7 +135,7 @@ extension BasePageCollectionCell { isOpened = isOpen if animated == true { - UIView.animate(withDuration: 0.3, delay: 0, options: UIViewAnimationOptions(), animations: { + UIView.animate(withDuration: 0.3, delay: 0, options: UIView.AnimationOptions(), animations: { self.contentView.layoutIfNeeded() }, completion: nil) } else { @@ -176,8 +176,8 @@ extension BasePageCollectionCell { contentView.insertSubview(shadow, belowSubview: view) // create constraints - let sizeConstaints: [(NSLayoutAttribute, CGFloat)] = [(NSLayoutAttribute.width, 0.8), (NSLayoutAttribute.height, 0.9)] - for info: (attribute: NSLayoutAttribute, scale: CGFloat) in sizeConstaints { + let sizeConstaints: [(NSLayoutConstraint.Attribute, CGFloat)] = [(NSLayoutConstraint.Attribute.width, 0.8), (NSLayoutConstraint.Attribute.height, 0.9)] + for info: (attribute: NSLayoutConstraint.Attribute, scale: CGFloat) in sizeConstaints { if let frontViewConstraint = view.getConstraint(info.attribute) { shadow >>>- { $0.attribute = info.attribute @@ -187,8 +187,8 @@ extension BasePageCollectionCell { } } - let centerConstraints: [(NSLayoutAttribute, CGFloat)] = [(NSLayoutAttribute.centerX, 0), (NSLayoutAttribute.centerY, 30)] - for info: (attribute: NSLayoutAttribute, offset: CGFloat) in centerConstraints { + let centerConstraints: [(NSLayoutConstraint.Attribute, CGFloat)] = [(NSLayoutConstraint.Attribute.centerX, 0), (NSLayoutConstraint.Attribute.centerY, 30)] + for info: (attribute: NSLayoutConstraint.Attribute, offset: CGFloat) in centerConstraints { (contentView, shadow, view) >>>- { $0.attribute = info.attribute $0.constant = info.offset diff --git a/Source/ExpandingViewController/CollectionView/Layout/PageCollectionLayout.swift b/Source/ExpandingViewController/CollectionView/Layout/PageCollectionLayout.swift index d1af76b..f656ac6 100644 --- a/Source/ExpandingViewController/CollectionView/Layout/PageCollectionLayout.swift +++ b/Source/ExpandingViewController/CollectionView/Layout/PageCollectionLayout.swift @@ -76,7 +76,7 @@ extension PageCollectionLayout { continue } - if fabs(attributes.center.x - proposedContentOffsetCenterX) < fabs(candidateAttributes!.center.x - proposedContentOffsetCenterX) { + if abs(attributes.center.x - proposedContentOffsetCenterX) < abs(candidateAttributes!.center.x - proposedContentOffsetCenterX) { candidateAttributes = attributes } } @@ -143,7 +143,7 @@ extension PageCollectionLayout { } let inset = collectionView.bounds.size.width / 2 - itemSize.width / 2 - collectionView.contentInset = UIEdgeInsetsMake(0, inset, 0, inset) + collectionView.contentInset = UIEdgeInsets.init(top: 0, left: inset, bottom: 0, right: inset) collectionView.contentOffset = CGPoint(x: -inset, y: 0) } } diff --git a/Source/ExpandingViewController/CollectionView/PageCollectionView.swift b/Source/ExpandingViewController/CollectionView/PageCollectionView.swift index cac3f70..8dbdb46 100644 --- a/Source/ExpandingViewController/CollectionView/PageCollectionView.swift +++ b/Source/ExpandingViewController/CollectionView/PageCollectionView.swift @@ -23,7 +23,7 @@ extension PageCollectionView { let collectionView = Init(PageCollectionView(frame: CGRect.zero, collectionViewLayout: layout)) { $0.translatesAutoresizingMaskIntoConstraints = false - $0.decelerationRate = UIScrollViewDecelerationRateFast + $0.decelerationRate = UIScrollView.DecelerationRate.fast $0.showsHorizontalScrollIndicator = false $0.dataSource = dataSource $0.delegate = delegate @@ -37,7 +37,7 @@ extension PageCollectionView { $0.constant = height return } - [NSLayoutAttribute.left, .right, .centerY].forEach { attribute in + [NSLayoutConstraint.Attribute.left, .right, .centerY].forEach { attribute in (view, collectionView) >>>- { $0.attribute = attribute return diff --git a/Source/Helpers/Animations/CornerAnimatable/CornerAnimatable.swift b/Source/Helpers/Animations/CornerAnimatable/CornerAnimatable.swift index 2255216..aa31ee7 100644 --- a/Source/Helpers/Animations/CornerAnimatable/CornerAnimatable.swift +++ b/Source/Helpers/Animations/CornerAnimatable/CornerAnimatable.swift @@ -18,7 +18,7 @@ extension CornerAnimatable where Self: UIView { let animation = Init(CABasicAnimation(keyPath: "cornerRadius")) { $0.duration = duration $0.toValue = radius - $0.fillMode = kCAFillModeForwards + $0.fillMode = CAMediaTimingFillMode.forwards $0.isRemovedOnCompletion = false } diff --git a/Source/Helpers/Constraints Helpers/ConstraintsHelper.swift b/Source/Helpers/Constraints Helpers/ConstraintsHelper.swift index e033e4b..1e9d51f 100644 --- a/Source/Helpers/Constraints Helpers/ConstraintsHelper.swift +++ b/Source/Helpers/Constraints Helpers/ConstraintsHelper.swift @@ -9,11 +9,11 @@ import UIKit struct ConstraintInfo { - var attribute: NSLayoutAttribute = .left - var secondAttribute: NSLayoutAttribute = .notAnAttribute + var attribute: NSLayoutConstraint.Attribute = .left + var secondAttribute: NSLayoutConstraint.Attribute = .notAnAttribute var constant: CGFloat = 0 var identifier: String? - var relation: NSLayoutRelation = .equal + var relation: NSLayoutConstraint.Relation = .equal } precedencegroup ConstOp { @@ -81,7 +81,7 @@ func >>>- (left: (T, T, T), block: (inout ConstraintInfo) -> Void) -> extension UIView { func addScaleToFillConstratinsOnView(_ view: UIView) { - [NSLayoutAttribute.left, .right, .top, .bottom].forEach { attribute in + [NSLayoutConstraint.Attribute.left, .right, .top, .bottom].forEach { attribute in (self, view) >>>- { $0.attribute = attribute return @@ -89,7 +89,7 @@ extension UIView { } } - func getConstraint(_ attributes: NSLayoutAttribute) -> NSLayoutConstraint? { + func getConstraint(_ attributes: NSLayoutConstraint.Attribute) -> NSLayoutConstraint? { return constraints.filter { if $0.firstAttribute == attributes && $0.secondItem == nil { return true diff --git a/Source/TransitionDriver/TransitionDriver.swift b/Source/TransitionDriver/TransitionDriver.swift index 22d7aba..429731e 100644 --- a/Source/TransitionDriver/TransitionDriver.swift +++ b/Source/TransitionDriver/TransitionDriver.swift @@ -71,7 +71,7 @@ extension TransitionDriver { copyView.center = view.center // constraints animation - UIView.animate(withDuration: duration, delay: 0, options: UIViewAnimationOptions(), animations: { + UIView.animate(withDuration: duration, delay: 0, options: UIView.AnimationOptions(), animations: { self.view.layoutIfNeeded() self.backImageView?.alpha = 1 self.copyCell?.shadowView?.alpha = 0 @@ -101,7 +101,7 @@ extension TransitionDriver { copyCell.backContainerView.animationCornerRadius(copyCell.backContainerView.layer.cornerRadius, duration: duration) copyCell.frontContainerView.animationCornerRadius(copyCell.frontContainerView.layer.cornerRadius, duration: duration) - UIView.animate(withDuration: duration, delay: 0, options: UIViewAnimationOptions(), animations: { + UIView.animate(withDuration: duration, delay: 0, options: UIView.AnimationOptions(), animations: { self.rightCell?.center.x -= self.step self.leftCell?.center.x += self.step @@ -132,7 +132,7 @@ extension TransitionDriver { view.addSubview(cell) // add constraints - [(NSLayoutAttribute.width, cell.bounds.size.width), (NSLayoutAttribute.height, cell.bounds.size.height)].forEach { info in + [(NSLayoutConstraint.Attribute.width, cell.bounds.size.width), (NSLayoutConstraint.Attribute.height, cell.bounds.size.height)].forEach { info in cell >>>- { $0.attribute = info.0 $0.constant = info.1 @@ -140,7 +140,7 @@ extension TransitionDriver { } } - [NSLayoutAttribute.centerX, .centerY].forEach { attribute in + [NSLayoutConstraint.Attribute.centerX, .centerY].forEach { attribute in (view, cell) >>>- { $0.attribute = attribute return @@ -159,7 +159,7 @@ extension TransitionDriver { view.addSubview(imageView) // add constraints - [NSLayoutAttribute.left, .right, .top, .bottom].forEach { attribute in + [NSLayoutConstraint.Attribute.left, .right, .top, .bottom].forEach { attribute in (view, imageView) >>>- { $0.attribute = attribute return diff --git a/expanding-collection.podspec b/expanding-collection.podspec index 6dc9d47..eb31f32 100644 --- a/expanding-collection.podspec +++ b/expanding-collection.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'expanding-collection' - s.version = '2.1.0' + s.version = '2.1.1' s.summary = 'Transition animtion from CollectionView to TableView' s.license = 'MIT' s.homepage = 'https://github.com/Ramotion/expanding-collection'