Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove support for older Swift versions #595

Merged
merged 1 commit into from
Sep 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 11 additions & 30 deletions Parchment/Classes/PagingOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,30 +106,16 @@ public struct PagingOptions {
/// view controller. _Default: .horizontal_
public var contentNavigationOrientation: PagingNavigationOrientation

#if swift(>=4.2)
public var scrollPosition: UICollectionView.ScrollPosition {
switch selectedScrollPosition {
case .left:
return UICollectionView.ScrollPosition.left
case .right:
return UICollectionView.ScrollPosition.right
case .preferCentered, .center:
return UICollectionView.ScrollPosition.centeredHorizontally
}
public var scrollPosition: UICollectionView.ScrollPosition {
switch selectedScrollPosition {
case .left:
return UICollectionView.ScrollPosition.left
case .right:
return UICollectionView.ScrollPosition.right
case .preferCentered, .center:
return UICollectionView.ScrollPosition.centeredHorizontally
}

#else
public var scrollPosition: UICollectionViewScrollPosition {
switch selectedScrollPosition {
case .left:
return UICollectionViewScrollPosition.left
case .right:
return UICollectionViewScrollPosition.right
case .preferCentered, .center:
return UICollectionViewScrollPosition.centeredHorizontally
}
}
#endif
}

public var menuHeight: CGFloat {
return menuItemSize.height + menuInsets.top + menuInsets.bottom
Expand Down Expand Up @@ -174,13 +160,8 @@ public struct PagingOptions {
insets: UIEdgeInsets(top: 0, left: 8, bottom: 0, right: 8)
)

#if swift(>=4.0)
font = UIFont.systemFont(ofSize: 15, weight: UIFont.Weight.medium)
selectedFont = UIFont.systemFont(ofSize: 15, weight: UIFont.Weight.medium)
#else
font = UIFont.systemFont(ofSize: 15, weight: UIFontWeightMedium)
selectedFont = UIFont.systemFont(ofSize: 15, weight: UIFontWeightMedium)
#endif
font = UIFont.systemFont(ofSize: 15, weight: UIFont.Weight.medium)
selectedFont = UIFont.systemFont(ofSize: 15, weight: UIFont.Weight.medium)

textColor = UIColor.black
selectedTextColor = UIColor(red: 3 / 255, green: 125 / 255, blue: 233 / 255, alpha: 1)
Expand Down
9 changes: 2 additions & 7 deletions Parchment/Classes/PagingSizeCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,8 @@ class PagingSizeCache {
init(options: PagingOptions) {
self.options = options

#if swift(>=4.2)
let didEnterBackground = UIApplication.didEnterBackgroundNotification
let didReceiveMemoryWarning = UIApplication.didReceiveMemoryWarningNotification
#else
let didEnterBackground = NSNotification.Name.UIApplicationDidEnterBackground
let didReceiveMemoryWarning = NSNotification.Name.UIApplicationDidReceiveMemoryWarning
#endif
let didEnterBackground = UIApplication.didEnterBackgroundNotification
let didReceiveMemoryWarning = UIApplication.didReceiveMemoryWarningNotification

NotificationCenter.default.addObserver(self,
selector: #selector(applicationDidEnterBackground(notification:)),
Expand Down
6 changes: 1 addition & 5 deletions Parchment/Classes/PagingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ open class PagingView: UIView {
"pageView": pageView,
]

#if swift(>=4.2)
let formatOptions = NSLayoutConstraint.FormatOptions()
#else
let formatOptions = NSLayoutFormatOptions()
#endif
let formatOptions = NSLayoutConstraint.FormatOptions()

let horizontalCollectionViewContraints = NSLayoutConstraint.constraints(
withVisualFormat: "H:|[collectionView]|",
Expand Down
12 changes: 3 additions & 9 deletions Parchment/Classes/PagingViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -477,15 +477,9 @@ open class PagingViewController:
open override func viewDidLoad() {
super.viewDidLoad()

#if swift(>=4.2)
addChild(pageViewController)
pagingView.configure()
pageViewController.didMove(toParent: self)
#else
addChildViewController(pageViewController)
pagingView.configure()
pageViewController.didMove(toParentViewController: self)
#endif
addChild(pageViewController)
pagingView.configure()
pageViewController.didMove(toParent: self)

pageViewController.delegate = self
pageViewController.dataSource = self
Expand Down
19 changes: 5 additions & 14 deletions Parchment/Structs/PagingDiff.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,11 @@ struct PagingDiff {
}

private func diff(visibleItems: PagingItems, cache: [Int: PagingItem]) -> [IndexPath] {
#if swift(>=4.1)
return visibleItems.items.compactMap { item in
if cache[item.identifier] == nil {
return visibleItems.indexPath(for: item)
}
return nil
}
#else
return visibleItems.items.flatMap { item in
if cache[item.hashValue] == nil {
return visibleItems.indexPath(for: item)
}
return nil
return visibleItems.items.compactMap { item in
if cache[item.identifier] == nil {
return visibleItems.indexPath(for: item)
}
#endif
return nil
}
}
}