diff --git a/Demo/TabPageViewControllerDemo/AppDelegate.swift b/Demo/TabPageViewControllerDemo/AppDelegate.swift index 56e1333..b525496 100644 --- a/Demo/TabPageViewControllerDemo/AppDelegate.swift +++ b/Demo/TabPageViewControllerDemo/AppDelegate.swift @@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. return true } diff --git a/Sources/TabCollectionCell.swift b/Sources/TabCollectionCell.swift index cc9a02d..6c869e9 100644 --- a/Sources/TabCollectionCell.swift +++ b/Sources/TabCollectionCell.swift @@ -10,7 +10,7 @@ import UIKit class TabCollectionCell: UICollectionViewCell { - var tabItemButtonPressedBlock: ((Void) -> Void)? + var tabItemButtonPressedBlock: (() -> Void)? var option: TabPageOption = TabPageOption() { didSet { currentBarViewHeightConstraint.constant = option.currentBarHeight @@ -47,7 +47,7 @@ class TabCollectionCell: UICollectionViewCell { } override func sizeThatFits(_ size: CGSize) -> CGSize { - if item.characters.count == 0 { + if item.count == 0 { return CGSize.zero } diff --git a/Sources/TabPageViewController.swift b/Sources/TabPageViewController.swift index 72f6c89..3caee10 100644 --- a/Sources/TabPageViewController.swift +++ b/Sources/TabPageViewController.swift @@ -17,7 +17,7 @@ open class TabPageViewController: UIPageViewController { guard let viewController = viewControllers?.first else { return nil } - return tabItems.map{ $0.viewController }.index(of: viewController) + return tabItems.map{ $0.viewController }.firstIndex(of: viewController) } fileprivate var beforeIndex: Int = 0 fileprivate var tabItemsCount: Int { @@ -80,7 +80,7 @@ open class TabPageViewController: UIPageViewController { public extension TabPageViewController { - public func displayControllerWithIndex(_ index: Int, direction: UIPageViewControllerNavigationDirection, animated: Bool) { + func displayControllerWithIndex(_ index: Int, direction: UIPageViewController.NavigationDirection, animated: Bool) { beforeIndex = index shouldScrollCurrentBar = false @@ -120,7 +120,7 @@ extension TabPageViewController { fileprivate func setupScrollView() { // Disable PageViewController's ScrollView bounce - let scrollView = view.subviews.flatMap { $0 as? UIScrollView }.first + let scrollView = view.subviews.compactMap { $0 as? UIScrollView }.first scrollView?.scrollsToTop = false scrollView?.delegate = self scrollView?.backgroundColor = option.pageBackgoundColor @@ -168,7 +168,7 @@ extension TabPageViewController { multiplier: 1.0, constant: 0.0) - let right = NSLayoutConstraint(item: view, + let right = NSLayoutConstraint(item: view as Any, attribute: .trailing, relatedBy: .equal, toItem: tabView, @@ -181,7 +181,7 @@ extension TabPageViewController { tabView.pageTabItems = tabItems.map({ $0.title}) tabView.updateCurrentIndex(beforeIndex, shouldScroll: true) - tabView.pageItemPressedBlock = { [weak self] (index: Int, direction: UIPageViewControllerNavigationDirection) in + tabView.pageItemPressedBlock = { [weak self] (index: Int, direction: UIPageViewController.NavigationDirection) in self?.displayControllerWithIndex(index, direction: direction, animated: true) } @@ -212,7 +212,7 @@ extension TabPageViewController { multiplier: 1.0, constant: 0.0) - let right = NSLayoutConstraint(item: view, + let right = NSLayoutConstraint(item: view as Any, attribute: .trailing, relatedBy: .equal, toItem: statusView, @@ -270,7 +270,7 @@ extension TabPageViewController { if option.hidesTopViewOnSwipeType != .none { tabBarTopConstraint.constant = 0.0 - UIView.animate(withDuration: TimeInterval(UINavigationControllerHideShowBarDuration)) { + UIView.animate(withDuration: TimeInterval(UINavigationController.hideShowBarDuration)) { self.view.layoutIfNeeded() } } @@ -283,7 +283,7 @@ extension TabPageViewController { guard let tabBarTopConstraint = tabBarTopConstraint else { return } tabBarTopConstraint.constant = hidden ? -(20.0 + option.tabHeight) : 0.0 - UIView.animate(withDuration: TimeInterval(UINavigationControllerHideShowBarDuration)) { + UIView.animate(withDuration: TimeInterval(UINavigationController.hideShowBarDuration)) { self.view.layoutIfNeeded() } } @@ -296,7 +296,7 @@ extension TabPageViewController: UIPageViewControllerDataSource { fileprivate func nextViewController(_ viewController: UIViewController, isAfter: Bool) -> UIViewController? { - guard var index = tabItems.map({$0.viewController}).index(of: viewController) else { + guard var index = tabItems.map({$0.viewController}).firstIndex(of: viewController) else { return nil } diff --git a/Sources/TabView.swift b/Sources/TabView.swift index 0a870b7..32ab6d9 100644 --- a/Sources/TabView.swift +++ b/Sources/TabView.swift @@ -10,7 +10,7 @@ import UIKit internal class TabView: UIView { - var pageItemPressedBlock: ((_ index: Int, _ direction: UIPageViewControllerNavigationDirection) -> Void)? + var pageItemPressedBlock: ((_ index: Int, _ direction: UIPageViewController.NavigationDirection) -> Void)? var pageTabItems: [String] = [] { didSet { pageTabItemsCount = pageTabItems.count @@ -47,7 +47,7 @@ internal class TabView: UIView { addSubview(contentView) contentView.backgroundColor = option.tabBackgroundColor.withAlphaComponent(option.tabBarAlpha) - let top = NSLayoutConstraint(item: contentView, + let top = NSLayoutConstraint(item: contentView as Any, attribute: .top, relatedBy: .equal, toItem: self, @@ -55,7 +55,7 @@ internal class TabView: UIView { multiplier: 1.0, constant: 0.0) - let left = NSLayoutConstraint(item: contentView, + let left = NSLayoutConstraint(item: contentView as Any, attribute: .leading, relatedBy: .equal, toItem: self, @@ -85,7 +85,7 @@ internal class TabView: UIView { let bundle = Bundle(for: TabView.self) let nib = UINib(nibName: TabCollectionCell.cellIdentifier(), bundle: bundle) collectionView.register(nib, forCellWithReuseIdentifier: TabCollectionCell.cellIdentifier()) - cellForSize = nib.instantiate(withOwner: nil, options: nil).first as! TabCollectionCell + cellForSize = nib.instantiate(withOwner: nil, options: nil).first as? TabCollectionCell collectionView.scrollsToTop = false @@ -95,7 +95,7 @@ internal class TabView: UIView { currentBarView.removeFromSuperview() collectionView.addSubview(currentBarView) currentBarView.translatesAutoresizingMaskIntoConstraints = false - let top = NSLayoutConstraint(item: currentBarView, + let top = NSLayoutConstraint(item: currentBarView as Any, attribute: .top, relatedBy: .equal, toItem: collectionView, @@ -103,7 +103,7 @@ internal class TabView: UIView { multiplier: 1.0, constant: option.tabHeight - currentBarViewHeightConstraint.constant) - let left = NSLayoutConstraint(item: currentBarView, + let left = NSLayoutConstraint(item: currentBarView as Any, attribute: .leading, relatedBy: .equal, toItem: collectionView, @@ -161,7 +161,7 @@ extension TabView { let distance = (currentCell.frame.width / 2.0) + (nextCell.frame.width / 2.0) let scrollRate = contentOffsetX / frame.width - if fabs(scrollRate) > 0.6 { + if abs(scrollRate) > 0.6 { nextCell.highlightTitle() currentCell.unHighlightTitle() } else { @@ -169,7 +169,7 @@ extension TabView { currentCell.highlightTitle() } - let width = fabs(scrollRate) * (nextCell.frame.width - currentCell.frame.width) + let width = abs(scrollRate) * (nextCell.frame.width - currentCell.frame.width) if isInfinity { let scroll = scrollRate * distance collectionView.contentOffset.x = collectionViewContentOffsetX + scroll @@ -277,7 +277,7 @@ extension TabView { fileprivate func deselectVisibleCells() { collectionView .visibleCells - .flatMap { $0 as? TabCollectionCell } + .compactMap { $0 as? TabCollectionCell } .forEach { $0.isCurrent = false } } } @@ -303,7 +303,7 @@ extension TabView: UICollectionViewDataSource { cell.option = option cell.isCurrent = fixedIndex == (currentIndex % pageTabItemsCount) cell.tabItemButtonPressedBlock = { [weak self, weak cell] in - var direction: UIPageViewControllerNavigationDirection = .forward + var direction: UIPageViewController.NavigationDirection = .forward if let pageTabItemsCount = self?.pageTabItemsCount, let currentIndex = self?.currentIndex { if self?.isInfinity == true { if (indexPath.item < pageTabItemsCount) || (indexPath.item < currentIndex) { diff --git a/TabPageViewController.xcodeproj/project.pbxproj b/TabPageViewController.xcodeproj/project.pbxproj index e15b023..ea25022 100644 --- a/TabPageViewController.xcodeproj/project.pbxproj +++ b/TabPageViewController.xcodeproj/project.pbxproj @@ -76,7 +76,7 @@ F8CE39F81F35AE6500CF74BA /* InfiniteTabPageViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = InfiniteTabPageViewController.swift; path = Demo/TabPageViewControllerDemo/InfiniteTabPageViewController.swift; sourceTree = ""; }; OBJ_12 /* TabPageViewControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabPageViewControllerTests.swift; sourceTree = ""; }; OBJ_14 /* TabPageViewController.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = TabPageViewController.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - OBJ_15 /* TabPageViewControllerTests.xctest */ = {isa = PBXFileReference; lastKnownFileType = file; path = TabPageViewControllerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + OBJ_15 /* TabPageViewControllerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; path = TabPageViewControllerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; OBJ_9 /* TabPageViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabPageViewController.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -279,6 +279,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -428,7 +429,7 @@ PRODUCT_BUNDLE_IDENTIFIER = jp.vasily.TabPageViewControllerDemo; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -474,7 +475,7 @@ PRODUCT_BUNDLE_IDENTIFIER = jp.vasily.TabPageViewControllerDemo; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -498,6 +499,7 @@ PRODUCT_BUNDLE_IDENTIFIER = TabPageViewController; PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)"; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SWIFT_VERSION = 5.0; TARGET_NAME = TabPageViewController; }; name = Debug; @@ -522,6 +524,7 @@ PRODUCT_BUNDLE_IDENTIFIER = TabPageViewController; PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)"; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SWIFT_VERSION = 5.0; TARGET_NAME = TabPageViewController; }; name = Release; @@ -539,6 +542,7 @@ LD_RUNPATH_SEARCH_PATHS = "@loader_path/../Frameworks"; OTHER_LDFLAGS = "$(inherited)"; OTHER_SWIFT_FLAGS = "$(inherited)"; + SWIFT_VERSION = 5.0; TARGET_NAME = TabPageViewControllerTests; }; name = Debug; @@ -556,6 +560,7 @@ LD_RUNPATH_SEARCH_PATHS = "@loader_path/../Frameworks"; OTHER_LDFLAGS = "$(inherited)"; OTHER_SWIFT_FLAGS = "$(inherited)"; + SWIFT_VERSION = 5.0; TARGET_NAME = TabPageViewControllerTests; }; name = Release; diff --git a/TabPageViewController.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/TabPageViewController.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/TabPageViewController.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Tests/TabPageViewControllerTests/TabPageViewControllerTests.swift b/Tests/TabPageViewControllerTests/TabPageViewControllerTests.swift index b98b886..ce08268 100644 --- a/Tests/TabPageViewControllerTests/TabPageViewControllerTests.swift +++ b/Tests/TabPageViewControllerTests/TabPageViewControllerTests.swift @@ -1,17 +1,2 @@ import XCTest @testable import TabPageViewController - -class TabPageViewControllerTests: XCTestCase { - func testExample() { - // This is an example of a functional test case. - // Use XCTAssert and related functions to verify your tests produce the correct results. - XCTAssertEqual(TabPageViewController().text, "Hello, World!") - } - - - static var allTests : [(String, (TabPageViewControllerTests) -> () throws -> Void)] { - return [ - ("testExample", testExample), - ] - } -}