Skip to content
This repository has been archived by the owner on Jun 17, 2018. It is now read-only.

Migrate to Swift 4.0 #366

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0
4.0
35 changes: 30 additions & 5 deletions PagingMenuController.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,12 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0640;
LastUpgradeCheck = 1010;
ORGANIZATIONNAME = kitasuke;
TargetAttributes = {
ECE530661B6DEB18001CF201 = {
CreatedOnToolsVersion = 6.4;
LastSwiftMigration = 1010;
};
};
};
Expand Down Expand Up @@ -194,20 +195,31 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
Expand All @@ -228,7 +240,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand All @@ -243,13 +255,23 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -269,7 +291,8 @@
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_VERSION = 3.0;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -281,6 +304,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -289,17 +313,18 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.yusuke.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
ECE5307F1B6DEB18001CF201 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -308,9 +333,9 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.yusuke.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0640"
LastUpgradeVersion = "1010"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -37,10 +37,10 @@
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand All @@ -62,15 +62,18 @@
ReferencedContainer = "container:PagingMenuController.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
Expand All @@ -85,10 +88,10 @@
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
Expand Down
2 changes: 1 addition & 1 deletion PagingMenuController/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>com.yusuke.$(PRODUCT_NAME:rfc1034identifier)</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
2 changes: 1 addition & 1 deletion Pod/Classes/MenuItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ extension MenuItemView {

fileprivate func estimatedLabelSize(_ label: UILabel) -> CGSize {
guard let text = label.text else { return .zero }
return NSString(string: text).boundingRect(with: CGSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude), options: .usesLineFragmentOrigin, attributes: [NSFontAttributeName: label.font], context: nil).size
return NSString(string: text).boundingRect(with: CGSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude), options: .usesLineFragmentOrigin, attributes: [NSAttributedString.Key.font: label.font], context: nil).size
}

fileprivate func calculateLabelSize(_ label: UILabel, maxWidth: CGFloat) -> CGSize {
Expand Down
9 changes: 8 additions & 1 deletion Pod/Classes/MenuView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ open class MenuView: UIScrollView {
internal init(menuOptions: MenuViewCustomizable) {
super.init(frame: CGRect(x: 0, y: 0, width: 0, height: menuOptions.height))

if #available(iOS 10.0, *) {
self.accessibilityTraits = UIAccessibilityTraits.tabBar
}

self.menuOptions = menuOptions

commonInit({ self.constructMenuItemViews(menuOptions) })
Expand Down Expand Up @@ -121,9 +125,12 @@ open class MenuView: UIScrollView {

if let previousMenuItemView = previousMenuItemView,
page != previousPage {
previousMenuItemView.titleLabel.accessibilityTraits = UIAccessibilityTraits.staticText
onMove?(.willMoveItem(to: menuItemView, from: previousMenuItemView))
}

menuItemView.titleLabel.accessibilityTraits = UIAccessibilityTraits.selected

update(currentPage: page)

let duration = animated ? menuOptions.animationDuration : 0
Expand Down Expand Up @@ -177,7 +184,7 @@ open class MenuView: UIScrollView {
bounces = menuViewBounces
isScrollEnabled = menuViewScrollEnabled
isDirectionalLockEnabled = true
decelerationRate = menuOptions.deceleratingRate
decelerationRate = UIScrollView.DecelerationRate(rawValue: menuOptions.deceleratingRate)
scrollsToTop = false
translatesAutoresizingMaskIntoConstraints = false
}
Expand Down
20 changes: 10 additions & 10 deletions Pod/Classes/PagingMenuController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ open class PagingMenuController: UIViewController {

pagingViewController.contentScrollView.delegate = self
view.addSubview(pagingViewController.view)
addChildViewController(pagingViewController)
pagingViewController.didMove(toParentViewController: self)
addChild(pagingViewController)
pagingViewController.didMove(toParent: self)
}
}
public var onMove: ((MenuMoveState) -> Void)? {
Expand Down Expand Up @@ -478,7 +478,7 @@ extension PagingMenuController {
menuView?.addGestureRecognizer(rightSwipeGestureRecognizer)
}

internal func handleTapGesture(_ recognizer: UITapGestureRecognizer) {
@objc internal func handleTapGesture(_ recognizer: UITapGestureRecognizer) {
guard let menuItemView = recognizer.view as? MenuItemView,
let menuView = menuView,
let page = menuView.menuItemViews.index(of: menuItemView),
Expand All @@ -503,19 +503,19 @@ extension PagingMenuController {
move(toPage: newPage)
}

internal func handleSwipeGesture(_ recognizer: UISwipeGestureRecognizer) {
@objc internal func handleSwipeGesture(_ recognizer: UISwipeGestureRecognizer) {
guard let menuView = recognizer.view as? MenuView,
let menuOptions = menuOptions else { return }

let newPage: Int
switch (recognizer.direction, menuOptions.displayMode) {
case (UISwipeGestureRecognizerDirection.left, .infinite):
case (UISwipeGestureRecognizer.Direction.left, .infinite):
newPage = menuView.nextPage
case (UISwipeGestureRecognizerDirection.left, _):
case (UISwipeGestureRecognizer.Direction.left, _):
newPage = min(nextPage, menuOptions.itemsOptions.count - 1)
case (UISwipeGestureRecognizerDirection.right, .infinite):
case (UISwipeGestureRecognizer.Direction.right, .infinite):
newPage = menuView.previousPage
case (UISwipeGestureRecognizerDirection.right, _):
case (UISwipeGestureRecognizer.Direction.right, _):
newPage = max(previousPage, 0)
default: return
}
Expand All @@ -533,8 +533,8 @@ extension PagingMenuController {
if let pagingViewController = self.pagingViewController {
pagingViewController.cleanup()
pagingViewController.view.removeFromSuperview()
pagingViewController.removeFromParentViewController()
pagingViewController.willMove(toParentViewController: nil)
pagingViewController.removeFromParent()
pagingViewController.willMove(toParent: nil)
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions Pod/Classes/PagingViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ open class PagingViewController: UIViewController {
if !shouldLoad(page: index) {
// remove unnecessary child view controllers
if isVisible(controller: controller) {
controller.willMove(toParentViewController: nil)
controller.willMove(toParent: nil)
controller.view!.removeFromSuperview()
controller.removeFromParentViewController()
controller.removeFromParent()

let _ = visibleControllers.index(of: controller).flatMap { visibleControllers.remove(at: $0) }
}
Expand All @@ -118,8 +118,8 @@ open class PagingViewController: UIViewController {
pagingView.translatesAutoresizingMaskIntoConstraints = false

contentScrollView.addSubview(pagingView)
addChildViewController(controller as UIViewController)
controller.didMove(toParentViewController: self)
addChild(controller as UIViewController)
controller.didMove(toParent: self)

visibleControllers.append(controller)
}
Expand Down Expand Up @@ -242,10 +242,10 @@ extension PagingViewController {
visibleControllers.removeAll(keepingCapacity: true)
currentViewController = nil

childViewControllers.forEach {
$0.willMove(toParentViewController: nil)
children.forEach {
$0.willMove(toParent: nil)
$0.view.removeFromSuperview()
$0.removeFromParentViewController()
$0.removeFromParent()
}

contentScrollView.removeFromSuperview()
Expand Down Expand Up @@ -276,7 +276,7 @@ extension PagingViewController {
}

fileprivate func isVisible(controller: UIViewController) -> Bool {
return self.childViewControllers.contains(controller)
return self.children.contains(controller)
}

fileprivate func hideVisibleControllers() {
Expand Down
2 changes: 1 addition & 1 deletion Pod/Classes/Protocols/MenuViewCustomizable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public extension MenuViewCustomizable {
return 0.3
}
var deceleratingRate: CGFloat {
return UIScrollViewDecelerationRateFast
return UIScrollView.DecelerationRate.fast.rawValue
}
var selectedItemCenter: Bool {
return true
Expand Down