From 5ff1f830ff905c25e5b9604316c87c5eb379b4fe Mon Sep 17 00:00:00 2001 From: kkiermasz Date: Sun, 13 Oct 2019 19:23:44 +0200 Subject: [PATCH] Update supported version to Swift 4.2 --- InfiniteCollectionView.xcodeproj/project.pbxproj | 9 +++++++++ .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ Sources/InfiniteCollectionView.swift | 10 +++++----- 3 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 InfiniteCollectionView.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/InfiniteCollectionView.xcodeproj/project.pbxproj b/InfiniteCollectionView.xcodeproj/project.pbxproj index 51d0cda..ea8e351 100644 --- a/InfiniteCollectionView.xcodeproj/project.pbxproj +++ b/InfiniteCollectionView.xcodeproj/project.pbxproj @@ -89,6 +89,11 @@ isa = PBXProject; attributes = { LastUpgradeCheck = 9999; + TargetAttributes = { + OBJ_17 = { + LastSwiftMigration = 1010; + }; + }; }; buildConfigurationList = OBJ_2 /* Build configuration list for PBXProject "InfiniteCollectionView" */; compatibilityVersion = "Xcode 3.2"; @@ -135,6 +140,8 @@ PRODUCT_BUNDLE_IDENTIFIER = InfiniteCollectionView; PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)"; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SWIFT_SWIFT3_OBJC_INFERENCE = Off; + SWIFT_VERSION = 4.2; TARGET_NAME = InfiniteCollectionView; }; name = Debug; @@ -155,6 +162,8 @@ PRODUCT_BUNDLE_IDENTIFIER = InfiniteCollectionView; PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)"; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SWIFT_SWIFT3_OBJC_INFERENCE = Off; + SWIFT_VERSION = 4.2; TARGET_NAME = InfiniteCollectionView; }; name = Release; diff --git a/InfiniteCollectionView.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/InfiniteCollectionView.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/InfiniteCollectionView.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Sources/InfiniteCollectionView.swift b/Sources/InfiniteCollectionView.swift index 5111dde..8b2a4ef 100644 --- a/Sources/InfiniteCollectionView.swift +++ b/Sources/InfiniteCollectionView.swift @@ -44,12 +44,12 @@ open class InfiniteCollectionView: UICollectionView { configure() } deinit { - NotificationCenter.default.removeObserver(self, name: .UIDeviceOrientationDidChange, object: nil) + NotificationCenter.default.removeObserver(self, name: UIDevice.orientationDidChangeNotification, object: nil) } - open func rotate(_ notification: Notification) { + @objc open func rotate(_ notification: Notification) { setContentOffset(CGPoint(x: CGFloat(pageIndex + indexOffset) * itemWidth, y: contentOffset.y), animated: false) } - open override func selectItem(at indexPath: IndexPath?, animated: Bool, scrollPosition: UICollectionViewScrollPosition) { + open override func selectItem(at indexPath: IndexPath?, animated: Bool, scrollPosition: UICollectionView.ScrollPosition) { guard let indexPath = indexPath else { return } // Correct the input IndexPath let correctedIndexPath = IndexPath(row: correctedIndex(indexPath.item + indexOffset), section: 0) @@ -84,13 +84,13 @@ private extension InfiniteCollectionView { delegate = self dataSource = self register(UICollectionViewCell.self, forCellWithReuseIdentifier: defaultIdentifier) - NotificationCenter.default.addObserver(self, selector: #selector(InfiniteCollectionView.rotate(_:)), name: .UIDeviceOrientationDidChange, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(InfiniteCollectionView.rotate(_:)), name: UIDevice.orientationDidChangeNotification, object: nil) } func centerIfNeeded(_ scrollView: UIScrollView) { let currentOffset = contentOffset let centerX = (scrollView.contentSize.width - bounds.width) / 2 let distFromCenter = centerX - currentOffset.x - if fabs(distFromCenter) > (totalContentWidth / 4) { + if abs(distFromCenter) > (totalContentWidth / 4) { let cellcount = distFromCenter / itemWidth let shiftCells = Int((cellcount > 0) ? floor(cellcount) : ceil(cellcount)) let offsetCorrection = (abs(cellcount).truncatingRemainder(dividingBy: 1)) * itemWidth