Skip to content

Commit

Permalink
Merge pull request #33 from iZettle/xcode-10.2
Browse files Browse the repository at this point in the history
Migrate to swift 5
  • Loading branch information
niil-ohlin committed Apr 1, 2019
2 parents 3b192e8 + 110b3f8 commit 940e0d4
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 42 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

test-iOS:
macos:
xcode: "10.1.0"
xcode: "10.2.0"
steps:
- checkout
- run:
Expand All @@ -29,7 +29,7 @@ jobs:
examples:
macos:
xcode: "10.1.0"
xcode: "10.2.0"
steps:
- checkout
- run:
Expand Down
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ disabled_rules:

- weak_delegate
- vertical_whitespace
- identifier_name

included:
- Presentation
Expand Down
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "iZettle/Flow" >= 1.3
github "iZettle/Flow" "1.7.0"
1 change: 1 addition & 0 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github "iZettle/Flow" "1.7.0"
17 changes: 9 additions & 8 deletions Presentation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -210,28 +210,29 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0830;
LastUpgradeCheck = 0930;
LastUpgradeCheck = 1020;
ORGANIZATIONNAME = iZettle;
TargetAttributes = {
F617E3741C197D5E00B567FB = {
CreatedOnToolsVersion = 7.2;
DevelopmentTeam = G94FN7ACW4;
LastSwiftMigration = 0900;
LastSwiftMigration = 1020;
ProvisioningStyle = Manual;
};
F6CB329B1F2F399600CA56C2 = {
CreatedOnToolsVersion = 8.3.3;
LastSwiftMigration = 0910;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
};
};
};
buildConfigurationList = F617E36F1C197D5E00B567FB /* Build configuration list for PBXProject "Presentation" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = F617E36B1C197D5E00B567FB;
productRefGroup = F617E3761C197D5E00B567FB /* Products */;
Expand Down Expand Up @@ -463,7 +464,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.iZettle.Presentation;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -482,7 +483,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.iZettle.Presentation;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand All @@ -505,7 +506,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -522,7 +523,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.izettle.PresentationTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.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 = "0930"
LastUpgradeVersion = "1020"
version = "1.3">
<BuildAction
parallelizeBuildables = "NO"
Expand Down
12 changes: 6 additions & 6 deletions Presentation/Alert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public struct Alert<Value> {
/// An action to be displayed
public struct Action {
public var title: String
public var style: UIAlertActionStyle
public var style: UIAlertAction.Style

/// A closure that produces the result of this action. It accepts an array of the current values of the action's fields as its parameter and returns a result value
public var action: ([String]) throws -> Value
Expand Down Expand Up @@ -69,14 +69,14 @@ public extension Alert {
}

public extension Alert.Action {
init(title: String, style: UIAlertActionStyle = .default, enabledPredicate: @escaping ([String]) -> Bool = { _ in true }, action: @escaping ([String]) throws -> Value) {
init(title: String, style: UIAlertAction.Style = .default, enabledPredicate: @escaping ([String]) -> Bool = { _ in true }, action: @escaping ([String]) throws -> Value) {
self.title = title
self.style = style
self.action = action
self.enabledPredicate = enabledPredicate
}

init(title: String, style: UIAlertActionStyle = .default, action: @escaping () throws -> Value) {
init(title: String, style: UIAlertAction.Style = .default, action: @escaping () throws -> Value) {
self.init(title: title, style: style, action: { (_: [String]) in try action() })
}
}
Expand Down Expand Up @@ -139,7 +139,7 @@ extension Alert: Presentable {
private var createSheetKey = false

private extension Alert {
func materialize(for preferredStyle: UIAlertControllerStyle) -> (UIAlertController, Future<Value>) {
func materialize(for preferredStyle: UIAlertController.Style) -> (UIAlertController, Future<Value>) {
let vc = UIAlertController(title: title, message: message, preferredStyle: preferredStyle)
vc.accessibilityLabel = title
vc.message = message
Expand Down Expand Up @@ -193,15 +193,15 @@ private extension Alert {
}

private extension UIAlertAction {
convenience init(title: String, style: UIAlertActionStyle = .default, actionHandler: ((UIAlertAction) -> Void)? = nil) {
convenience init(title: String, style: UIAlertAction.Style = .default, actionHandler: ((UIAlertAction) -> Void)? = nil) {
self.init(title: title, style: style, handler: actionHandler)
// No accessibilityIdentifier avaialble on UIAlertAction, so we only set the localized accessibilityLabel instead
accessibilityLabel = title
}
}

private extension UIAlertController {
func addActionWithTitle(_ title: String, style: UIAlertActionStyle = .default) -> Signal<()> {
func addActionWithTitle(_ title: String, style: UIAlertAction.Style = .default) -> Signal<()> {
let callbacker = Callbacker<()>()
let action = UIAlertAction(title: title, style: style) { _ in callbacker.callAll(with: ()) }

Expand Down
2 changes: 1 addition & 1 deletion Presentation/DismissInstallable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public extension UIViewController {
}

return Disposer {
guard let index = self.navigationItem.leftBarButtonItems?.index(of: barItem) else { return }
guard let index = self.navigationItem.leftBarButtonItems?.firstIndex(of: barItem) else { return }
self.navigationItem.leftBarButtonItems?.remove(at: index)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Presentation/DualNavigationControllersSplitDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ open class DualNavigationControllersSplitDelegate: NSObject, UISplitViewControll
return nc
}

open func targetDisplayModeForAction(in svc: UISplitViewController) -> UISplitViewControllerDisplayMode {
open func targetDisplayModeForAction(in svc: UISplitViewController) -> UISplitViewController.DisplayMode {
isCollapsedProperty.value = svc.isViewLoaded && svc.view.window != nil ? svc.isCollapsed : true

if svc.viewControllers.isEmpty {
Expand Down
6 changes: 3 additions & 3 deletions Presentation/KeepSelection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,21 @@ public final class KeepSelection<Elements: BidirectionalCollection>: SignalProvi
}

let oldItem = oldElements[oldIndex]
if let newIndex = elements.index(where: { isSame($0, oldItem) }) {
if let newIndex = elements.firstIndex(where: { isSame($0, oldItem) }) {
return (elements, newIndex)
}

// Search forward to see if any of the items in old is still in new
for oldItem in oldElements[oldElements.index(after: oldIndex)..<oldElements.endIndex] {
guard let index = elements.index(where: { isSame($0, oldItem) }) else {
guard let index = elements.firstIndex(where: { isSame($0, oldItem) }) else {
continue
}
return (elements, index)
}

// Search backward to see if any of the items in old is still in new
for oldItem in oldElements[oldElements.startIndex..<oldIndex].reversed() {
guard let index = elements.index(where: { isSame($0, oldItem) }) else {
guard let index = elements.firstIndex(where: { isSame($0, oldItem) }) else {
continue
}
let nextIndex = elements.index(after: index)
Expand Down
4 changes: 2 additions & 2 deletions Presentation/MasterDetailSelection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public extension SignalProvider where Value: BidirectionalCollection {
typealias Element = Value.Iterator.Element
func index(before element: Element, isSame: @escaping (Element, Element) -> Bool) -> CoreSignal<Kind.DropWrite, Value.Index?> {
return map { collection in
guard let index = collection.index(where: { isSame(element, $0) }), index != collection.startIndex else { return nil }
guard let index = collection.firstIndex(where: { isSame(element, $0) }), index != collection.startIndex else { return nil }
return collection.index(before: index)
}
}
Expand All @@ -208,7 +208,7 @@ public extension SignalProvider where Value: Collection {
/// Returns a signal that will signal when index after `element` is updated.
func index(after element: Element, isSame: @escaping (Element, Element) -> Bool) -> CoreSignal<Kind.DropWrite, Value.Index?> {
return map { collection in
guard let index = collection.index(where: { isSame(element, $0) }) else { return nil }
guard let index = collection.firstIndex(where: { isSame(element, $0) }) else { return nil }
let next = collection.index(after: index)
return next != collection.endIndex ? next : nil
}
Expand Down
8 changes: 4 additions & 4 deletions Presentation/PresentationStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public extension PresentationStyle {
let bag = DisposeBag()

let parentView: ReadSignal<UIView> = view.map { ReadSignal($0) } ?? vc.signal(for: \.view).map { $0! }
from.addChildViewController(vc)
from.addChild(vc)

var movedToParent = false
bag += parentView.atOnce().onValueDisposePrevious { parentView in
Expand All @@ -179,7 +179,7 @@ public extension PresentationStyle {
vc.view.layoutIfNeeded()
}
if !movedToParent {
vc.didMove(toParentViewController: from)
vc.didMove(toParent: from)
movedToParent = true
}
}
Expand All @@ -196,9 +196,9 @@ public extension PresentationStyle {
}

return (result, {
vc.willMove(toParentViewController: nil)
vc.willMove(toParent: nil)
vc.view.removeFromSuperview()
vc.removeFromParentViewController()
vc.removeFromParent()
return Future()
})
}
Expand Down
16 changes: 8 additions & 8 deletions Presentation/UINavigationController+Presenting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ import Flow

public extension PresentationOptions {
/// Pushing and popping on a navigation controller defaults to batch subsequent operation from the same run-loop togeher. This options turnes that of.
public static let disablePushPopCoalecing = PresentationOptions()
static let disablePushPopCoalecing = PresentationOptions()

/// Automatically pop a pushed view controller once the presentation completes.
public static let autoPop = PresentationOptions()
static let autoPop = PresentationOptions()

/// Any succeedingly pushed view controllers (pushed after itself) will be popped when `self` is cancelled or completed.
public static let autoPopSuccessors = PresentationOptions()
static let autoPopSuccessors = PresentationOptions()

/// Equivalent to [.autoPop, .autoPopSuccessors]
public static let autoPopSelfAndSuccessors: PresentationOptions = [.autoPop, .autoPopSuccessors]
static let autoPopSelfAndSuccessors: PresentationOptions = [.autoPop, .autoPopSuccessors]
}

extension UINavigationController: PresentingViewController {
Expand All @@ -35,7 +35,7 @@ extension UINavigationController: PresentingViewController {
futures.append(nc.popViewController(vc, options: options))
}

if let index = nc.viewControllers.index(of: vc), options.contains(.autoPopSuccessors) {
if let index = nc.viewControllers.firstIndex(of: vc), options.contains(.autoPopSuccessors) {
for vc in nc.viewControllers.suffix(from: index).dropFirst() {
futures.append(nc.popViewController(vc, options: options))
}
Expand Down Expand Up @@ -112,7 +112,7 @@ private extension UINavigationController {
}

func append(_ pushPoper: PushPoper) {
if let i = pushPopers.index(where: { $0.vc == pushPoper.vc && !$0.isPopping }), pushPoper.isPopping {
if let i = pushPopers.firstIndex(where: { $0.vc == pushPoper.vc && !$0.isPopping }), pushPoper.isPopping {
pushPopers.remove(at: i)
return
}
Expand All @@ -136,11 +136,11 @@ private extension UINavigationController {
for pushPoper in pushPopers {
animated = animated || pushPoper.animated
if pushPoper.isPopping {
_ = vcs.index(of: pushPoper.vc).map { vcs.remove(at: $0) }
_ = vcs.firstIndex(of: pushPoper.vc).map { vcs.remove(at: $0) }
} else {
guard !vcs.contains(pushPoper.vc) else {
pushPoper.onComplete(.failure(PresentError.alreadyPresented))
if let i = pushPopers.index(of: pushPoper) {
if let i = pushPopers.firstIndex(of: pushPoper) {
pushPopers.remove(at: i)
}
continue
Expand Down
2 changes: 1 addition & 1 deletion Presentation/UIViewController+Presentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public extension UIViewController {
func log(_ message: @escaping @autoclosure () -> String,
data: @escaping @autoclosure () -> String? = nil,
file: String = #file, function: String = #function, line: Int = #line) {
presentableLogPresentation(message, data, file, function, line)
presentableLogPresentation(message(), data(), file, function, line)
}

var unitTestDisablePresentWaitForWindow = false
Expand Down
4 changes: 2 additions & 2 deletions PresentationFramework.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Pod::Spec.new do |s|

s.ios.deployment_target = "9.0"
s.dependency 'FlowFramework', '>= 1.3'

s.source = { :git => "https://github.com/iZettle/Presentation.git", :tag => "#{s.version}" }
s.source_files = "Presentation/*.{swift}"
s.swift_version = '4.1'
s.swift_version = '5.0'
end
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ set -o pipefail
PROJECT="Presentation.xcodeproj"
SCHEME="Presentation"

IOS_SDK="iphonesimulator12.1"
IOS_DESTINATION_PHONE="OS=12.1,name=iPhone X"
IOS_SDK="iphonesimulator12.2"
IOS_DESTINATION_PHONE="OS=12.2,name=iPhone X"

usage() {
cat << EOF
Expand Down

0 comments on commit 940e0d4

Please sign in to comment.