Skip to content

Commit bb689dc

Browse files
[master] - 'Add convenience for the Never Swift Type so FlowRepresentables can declare they do not take in data - TT'
1 parent df3528f commit bb689dc

File tree

6 files changed

+44
-10
lines changed

6 files changed

+44
-10
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
language: swift
2-
osx_image: xcode10.3
2+
osx_image: xcode11.1
33
xcode_workspace: Workflow.xcworkspace
44
xcode_scheme: Workflow
55
xcode_destination: platform=iOS Simulator,name=iPhone 8

Podfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ PODS:
22
- CwlCatchException (1.0.2)
33
- CwlPreconditionTesting (1.1.1):
44
- CwlCatchException
5-
- DynamicWorkflow (0.0.3)
5+
- DynamicWorkflow (0.0.7)
66
- UIUTest (1.6.0)
77

88
DEPENDENCIES:
@@ -12,7 +12,7 @@ DEPENDENCIES:
1212
- UIUTest
1313

1414
SPEC REPOS:
15-
https://github.com/cocoapods/specs.git:
15+
trunk:
1616
- UIUTest
1717

1818
EXTERNAL SOURCES:
@@ -36,9 +36,9 @@ CHECKOUT OPTIONS:
3636
SPEC CHECKSUMS:
3737
CwlCatchException: 70a52ae44ea5d46db7bd385f801a94942420cd8c
3838
CwlPreconditionTesting: d33a4e4f285c0b885fddcae5dfedfbb34d4f3961
39-
DynamicWorkflow: a45e06c1d0448d295ed3572ccc591a347fe40237
39+
DynamicWorkflow: 214b6218b7e17dc458c865ea5f09436bf4922da5
4040
UIUTest: 842c642e5bec098b1e2c890cbe25aacab80f2481
4141

4242
PODFILE CHECKSUM: 5f55f064de83e2e4f31f04427448900a8e9571f2
4343

44-
COCOAPODS: 1.7.5
44+
COCOAPODS: 1.8.3

Workflow/Protocols/FlowRepresentable.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,23 @@ public protocol FlowRepresentable: AnyFlowRepresentable {
4444
/// - Parameter args: Note you can rename this in your implementation if 'args' doesn't make sense. If a previous item in a workflow tries to pass a type that does not match `shouldLoad` will automatically be false, and this method will not be called.
4545
/// - Returns: Void
4646
/// - Note: This method is called *before* your view loads. Do not attempt to do any UI work in this method. This is however a good place to set up data on your view.
47-
func shouldLoad(with args:IntakeType) -> Bool
47+
mutating func shouldLoad(with args:IntakeType) -> Bool
48+
}
49+
50+
extension FlowRepresentable where IntakeType == Never {
51+
mutating func erasedShouldLoad(with args: Any?) -> Bool {
52+
return shouldLoad()
53+
}
54+
55+
mutating func shouldLoad(with args: Never) -> Bool {}
56+
57+
func shouldLoad() -> Bool {
58+
return true
59+
}
4860
}
4961

5062
public extension FlowRepresentable {
51-
func erasedShouldLoad(with args:Any?) -> Bool {
63+
mutating func erasedShouldLoad(with args:Any?) -> Bool {
5264
guard let cast = args as? IntakeType else { return false }
5365
return shouldLoad(with: cast)
5466
}

Workflow/Protocols/TypeErased/AnyFlowRepresentable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public protocol AnyFlowRepresentable {
1919
var workflow:Workflow? { get set }
2020
var callback:((Any?) -> Void)? { get set }
2121

22-
func erasedShouldLoad(with args:Any?) -> Bool
22+
mutating func erasedShouldLoad(with args:Any?) -> Bool
2323

2424
/// instance: A method to return an instance of the `FlowRepresentable`
2525
/// - Returns: `AnyFlowRepresentable`. Specifically a new instance from the static class passed to a `Workflow`

WorkflowTests/UIKitPresenterTests.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,26 @@ class UIKitPresenterTests: XCTestCase {
10201020
XCTAssert(UIApplication.topViewController() is ExpectedModal, "Top View was not a modal")
10211021
XCTAssertNil((UIApplication.topViewController() as? ExpectedModal)?.navigationController, "You didn't present modally")
10221022
}
1023+
1024+
func testFlowRepresentableThatDoesNotTakeInData() {
1025+
class ExpectedController: UIWorkflowItem<Never>, FlowRepresentable {
1026+
static func instance() -> AnyFlowRepresentable {
1027+
let controller = ExpectedController()
1028+
controller.view.backgroundColor = .green
1029+
return controller
1030+
}
1031+
}
1032+
1033+
let rootController = UIViewController()
1034+
loadView(controller: rootController)
1035+
1036+
rootController.launchInto(Workflow([ExpectedController.self]), withLaunchStyle: .navigationStack)
1037+
RunLoop.current.singlePass()
1038+
1039+
XCTAssert(rootController.mostRecentlyPresentedViewController is UINavigationController, "mostRecentlyPresentedViewController should be nav controller: \(String(describing: rootController.mostRecentlyPresentedViewController))")
1040+
XCTAssertEqual((rootController.mostRecentlyPresentedViewController as? UINavigationController)?.viewControllers.count, 1)
1041+
XCTAssert((rootController.mostRecentlyPresentedViewController as? UINavigationController)?.viewControllers.first is ExpectedController)
1042+
}
10231043
}
10241044

10251045
extension UIKitPresenterTests {

WorkflowTests/WorkflowTests.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ class WorkflowTests: XCTestCase {
6161
}
6262
}
6363
let flow:[AnyFlowRepresentable.Type] = [FR1.self, FR2.self]
64-
_ = flow.first?.instance().erasedShouldLoad(with: "str")
65-
_ = flow.last?.instance().erasedShouldLoad(with: 1)
64+
var first = flow.first?.instance()
65+
var last = flow.last?.instance()
66+
_ = first?.erasedShouldLoad(with: "str")
67+
_ = last?.erasedShouldLoad(with: 1)
6668

6769
XCTAssert(FR1.shouldLoadCalledOnFR1, "Should load not called on flow representable 1 with correct corresponding type")
6870
XCTAssert(FR2.shouldLoadCalledOnFR2, "Should load not called on flow representable 2 with correct corresponding type")

0 commit comments

Comments
 (0)