Skip to content

Commit

Permalink
swift 4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
tarunon committed Oct 1, 2018
1 parent 489b190 commit 26b7613
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 23 deletions.
22 changes: 15 additions & 7 deletions Mew.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
D2568DF4214BCA3B00FCA44A /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D2568DF2214BCA3B00FCA44A /* Main.storyboard */; };
D2568DF6214BCA3C00FCA44A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D2568DF5214BCA3C00FCA44A /* Assets.xcassets */; };
D2568DF9214BCA3C00FCA44A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D2568DF7214BCA3C00FCA44A /* LaunchScreen.storyboard */; };
D25C01C821620C0100935A18 /* BackwardCompatibility.swift in Sources */ = {isa = PBXBuildFile; fileRef = D25C01C721620C0100935A18 /* BackwardCompatibility.swift */; };
D279A3072136B34E007B045A /* Instantiatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = D279A3062136B34E007B045A /* Instantiatable.swift */; };
D279A30A2136B357007B045A /* Injectable.swift in Sources */ = {isa = PBXBuildFile; fileRef = D279A3082136B357007B045A /* Injectable.swift */; };
D279A30B2136B357007B045A /* Interactable.swift in Sources */ = {isa = PBXBuildFile; fileRef = D279A3092136B357007B045A /* Interactable.swift */; };
Expand Down Expand Up @@ -64,6 +65,7 @@
D2568DF5214BCA3C00FCA44A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
D2568DF8214BCA3C00FCA44A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
D2568DFA214BCA3C00FCA44A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
D25C01C721620C0100935A18 /* BackwardCompatibility.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackwardCompatibility.swift; sourceTree = "<group>"; };
D279A3062136B34E007B045A /* Instantiatable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Instantiatable.swift; sourceTree = "<group>"; };
D279A3082136B357007B045A /* Injectable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Injectable.swift; sourceTree = "<group>"; };
D279A3092136B357007B045A /* Interactable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Interactable.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -130,6 +132,14 @@
path = Tests/MewTestsApp;
sourceTree = "<group>";
};
D25C01C621620BEC00935A18 /* Utils */ = {
isa = PBXGroup;
children = (
D25C01C721620C0100935A18 /* BackwardCompatibility.swift */,
);
path = Utils;
sourceTree = "<group>";
};
D279A3042136B31A007B045A /* Protocols */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -211,6 +221,7 @@
OBJ_8 /* Mew */ = {
isa = PBXGroup;
children = (
D25C01C621620BEC00935A18 /* Utils */,
D279A3042136B31A007B045A /* Protocols */,
D279A3052136B31F007B045A /* ContainerView */,
D2568DD7214BC00A00FCA44A /* Cells */,
Expand Down Expand Up @@ -288,7 +299,7 @@
ProvisioningStyle = Automatic;
};
"Mew::Mew" = {
LastSwiftMigration = 0940;
LastSwiftMigration = 1000;
};
"Mew::MewTests" = {
TestTargetID = D2568DEB214BCA3B00FCA44A;
Expand Down Expand Up @@ -344,6 +355,7 @@
files = (
D2568DDF214BC3DC00FCA44A /* CollectionViewCell.swift in Sources */,
D2568DE1214BC51E00FCA44A /* CollectionReusableView.swift in Sources */,
D25C01C821620C0100935A18 /* BackwardCompatibility.swift in Sources */,
D279A3192136B726007B045A /* _ContainerInterfaceBuilderView.xib in Sources */,
D2568DDD214BC32D00FCA44A /* TableViewHeaderFooterView.swift in Sources */,
D279A30E2136B365007B045A /* ContainerView.swift in Sources */,
Expand Down Expand Up @@ -458,7 +470,6 @@
PRODUCT_BUNDLE_IDENTIFIER = com.mercari.ios.MewTestsApp;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand Down Expand Up @@ -514,7 +525,6 @@
MTL_ENABLE_DEBUG_INFO = NO;
PRODUCT_BUNDLE_IDENTIFIER = com.mercari.ios.MewTestsApp;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
Expand All @@ -540,7 +550,6 @@
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
TARGET_NAME = Mew;
};
name = Debug;
Expand All @@ -564,7 +573,6 @@
PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)";
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.0;
TARGET_NAME = Mew;
};
name = Release;
Expand All @@ -588,6 +596,7 @@
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = SWIFT_PACKAGE;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.2;
USE_HEADERMAP = NO;
};
name = Debug;
Expand All @@ -606,7 +615,6 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @loader_path/../Frameworks @loader_path/Frameworks";
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited)";
SWIFT_VERSION = 4.0;
TARGET_NAME = MewTests;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MewTestsApp.app/MewTestsApp";
};
Expand All @@ -626,7 +634,6 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @loader_path/../Frameworks @loader_path/Frameworks";
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited)";
SWIFT_VERSION = 4.0;
TARGET_NAME = MewTests;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MewTestsApp.app/MewTestsApp";
};
Expand All @@ -649,6 +656,7 @@
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = SWIFT_PACKAGE;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.2;
USE_HEADERMAP = NO;
};
name = Release;
Expand Down
5 changes: 3 additions & 2 deletions MewExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@
TargetAttributes = {
D243A16B2136E4C400B075CC = {
CreatedOnToolsVersion = 9.4.1;
LastSwiftMigration = 1000;
};
};
};
Expand Down Expand Up @@ -410,7 +411,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = com.mercari.ios.MewExample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -428,7 +429,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = com.mercari.ios.MewExample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
4 changes: 2 additions & 2 deletions Sources/Mew/Cells/CollectionReusableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public enum CollectionViewSupplementaryKind {

var rawValue: String {
switch self {
case .header: return UICollectionElementKindSectionHeader
case .footer: return UICollectionElementKindSectionFooter
case .header: return UICollectionView.elementKindSectionHeader
case .footer: return UICollectionView.elementKindSectionFooter
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions Sources/Mew/ContainerView/ContainerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,27 @@ public class ContainerView: UIStackView {
/// When calling this function arbitrarily, arranged of ViewController by container is not guaranteed.
public func addArrangedViewController(_ viewController: UIViewController, parentViewController: UIViewController) {
viewController.view.translatesAutoresizingMaskIntoConstraints = false
parentViewController.addChildViewController(viewController)
parentViewController.addChild(viewController)
addArrangedSubview(viewController.view)
viewController.didMove(toParentViewController: parentViewController)
viewController.didMove(toParent: parentViewController)
}

/// The viewController will be inserted at the specified index as a childViewController of parentViewController that self (`ContainerView`)
/// When calling this function arbitrarily, arranged of ViewController by container is not guaranteed.
public func insertArrangedViewController(_ viewController: UIViewController, stackIndex: Int, parentViewController: UIViewController) {
viewController.view.translatesAutoresizingMaskIntoConstraints = false
parentViewController.addChildViewController(viewController)
parentViewController.addChild(viewController)
insertArrangedSubview(viewController.view, at: stackIndex)
viewController.didMove(toParentViewController: parentViewController)
viewController.didMove(toParent: parentViewController)
}

/// The viewController will be removed from self (`ContainerView`)
/// When calling this function arbitrarily, arranged of ViewController by container is not guaranteed.
public func removeArrangedViewController(_ viewController: UIViewController) {
viewController.willMove(toParentViewController: nil)
viewController.willMove(toParent: nil)
removeArrangedSubview(viewController.view)
viewController.view.removeFromSuperview()
viewController.removeFromParentViewController()
viewController.removeFromParent()
}
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/Mew/Protocols/CellProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ extension CellProtocol where Self: UIView {
internal func _willMove(to newSuperview: UIView?) {
guard let contentViewController = contentViewController else { return }
if newSuperview == nil {
contentViewController.willMove(toParentViewController: parentViewController)
contentViewController.willMove(toParent: parentViewController)
} else {
parentViewController?.addChildViewController(contentViewController)
parentViewController?.addChild(contentViewController)
}
}

internal func _didMoveToSuperview() {
guard let contentViewController = contentViewController else { return }
if superview == nil {
contentViewController.removeFromParentViewController()
contentViewController.removeFromParent()
} else {
contentViewController.didMove(toParentViewController: parentViewController)
contentViewController.didMove(toParent: parentViewController)
}
}
}
Expand Down
42 changes: 42 additions & 0 deletions Sources/Mew/Utils/BackwardCompatibility.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// BackwardCompatibility.swift
// Mew
//
// Created by tarunon on 2018/10/01.
// Copyright © 2018年 Mercari. All rights reserved.
//

import UIKit

#if swift(>=4.2)
#else

extension UIViewController {
func addChild(_ childViewController: UIViewController) {
addChildViewController(childViewController)
}

func willMove(toParent newParent: UIViewController?) {
willMove(toParentViewController: newParent)
}

func didMove(toParent newParent: UIViewController?) {
didMove(toParentViewController: newParent)
}

func removeFromParent() {
removeFromParentViewController()
}
}

extension UICollectionView {
static var elementKindSectionHeader: String {
return UICollectionElementKindSectionHeader
}

static var elementKindSectionFooter: String {
return UICollectionElementKindSectionFooter
}
}

#endif
10 changes: 8 additions & 2 deletions Sources/MewExample/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@

import UIKit

#if swift(>=4.2)
#else
extension UIApplication {
typealias LaunchOptionsKey = UIApplicationLaunchOptionsKey
}
#endif

@UIApplicationMain
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 {
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = UINavigationController(rootViewController: MainViewController(with: (), environment: EnvironmentMock()))
self.window?.makeKeyAndVisible()
Expand Down

0 comments on commit 26b7613

Please sign in to comment.