Skip to content

Commit

Permalink
Merge pull request #30 from BottleRocketStudios/feature/swift4.2
Browse files Browse the repository at this point in the history
Add out-of-box support for Swift 4.2.
  • Loading branch information
wmcginty committed Aug 17, 2018
2 parents e394935 + 5dbc467 commit 484a93b
Show file tree
Hide file tree
Showing 4 changed files with 925 additions and 895 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ public extension ContainerViewController {
// MARK: Removing a ManagedChild
func removeChild(_ child: ManagedChild) {
let removed = managedChildren.index { $0.identifier == child.identifier }.flatMap { managedChildren.remove(at: $0) }
#if swift(>=4.2)
removed?.viewController.removeFromParent()
#else
removed?.viewController.removeFromParentViewController()
#endif
}

func removeChildren(where predicate: (ManagedChild) -> Bool) {
Expand Down
12 changes: 12 additions & 0 deletions Sources/UtiliKit/Container/ContainerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,15 @@ private extension ContainerViewController {
func prepareForTransitioning(from source: UIViewController?, to destination: UIViewController, animated: Bool) {
isTransitioning = true

#if swift(>=4.2)
source?.willMove(toParent: nil)
destination.willMove(toParent: self)
addChild(destination)
#else
source?.willMove(toParentViewController: nil)
destination.willMove(toParentViewController: self)
addChildViewController(destination)
#endif
}

func configure(destinationView: UIView, inContainer container: UIView) {
Expand All @@ -124,9 +130,15 @@ private extension ContainerViewController {

func finishTransitioning(from source: UIViewController?, to destination: UIViewController, animated: Bool) {
source?.view.removeFromSuperview()
#if swift(>=4.2)
source?.removeFromParent()
source?.didMove(toParent: nil)
destination.didMove(toParent: self)
#else
source?.removeFromParentViewController()
source?.didMove(toParentViewController: nil)
destination.didMove(toParentViewController: self)
#endif

visibleController = destination
isTransitioning = false
Expand Down
14 changes: 12 additions & 2 deletions Sources/UtiliKit/Instantiation/UICollectionView+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,18 @@ public extension UICollectionView {
/// Either UICollectionElementKindSectionHeader or UICollectionElementKindSectionFooter
var type: String {
switch self {
case .sectionHeader: return UICollectionElementKindSectionHeader
case .sectionFooter: return UICollectionElementKindSectionFooter
case .sectionHeader:
#if swift(>=4.2)
return UICollectionView.elementKindSectionHeader
#else
return UICollectionElementKindSectionHeader
#endif
case .sectionFooter:
#if swift(>=4.2)
return UICollectionView.elementKindSectionFooter
#else
return UICollectionElementKindSectionFooter
#endif
}
}
}
Expand Down
Loading

0 comments on commit 484a93b

Please sign in to comment.