From e92d3f1ef8def9fbae862758fe111e26e1ccb45f Mon Sep 17 00:00:00 2001 From: Richard Gist Date: Fri, 4 Nov 2022 14:03:46 -0600 Subject: [PATCH 1/4] Fix IRGen crash by removing storing UIButton on test VC --- .../SwiftUIExampleTests/UIKitInteropTests.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ExampleApps/SwiftUIExample/SwiftUIExampleTests/UIKitInteropTests.swift b/ExampleApps/SwiftUIExample/SwiftUIExampleTests/UIKitInteropTests.swift index 154a2a92f..198bc385c 100644 --- a/ExampleApps/SwiftUIExample/SwiftUIExampleTests/UIKitInteropTests.swift +++ b/ExampleApps/SwiftUIExample/SwiftUIExampleTests/UIKitInteropTests.swift @@ -99,13 +99,12 @@ final class UIKitInteropTests: XCTestCase, View { func testPuttingAUIKitViewThatDoesNotTakeInDataInsideASwiftUIWorkflow() async throws { final class FR1: UIWorkflowItem, FlowRepresentable { - let nextButton = UIButton() - @objc private func nextPressed() { proceedInWorkflow() } override func viewDidLoad() { + let nextButton = UIButton() nextButton.setTitle("Next", for: .normal) nextButton.setTitleColor(.systemBlue, for: .normal) nextButton.addTarget(self, action: #selector(nextPressed), for: .touchUpInside) @@ -143,8 +142,9 @@ final class UIKitInteropTests: XCTestCase, View { proceedCalled.fulfill() } - XCTAssertEqual(vc.nextButton.willRespondToUser, true) - vc.nextButton.simulateTouch() + let nextButton = try XCTUnwrap(vc.view.subviews.first { $0 is UIButton } as? UIButton) + XCTAssertEqual(nextButton.willRespondToUser, true) + nextButton.simulateTouch() wait(for: [proceedCalled], timeout: TestConstant.timeout) } From 296bf11a752be764ce8c3103b3bb633b6f5bc038 Mon Sep 17 00:00:00 2001 From: Richard Gist Date: Fri, 4 Nov 2022 14:09:43 -0600 Subject: [PATCH 2/4] Get nextButton through tag for added assurance the correct button was found --- .../SwiftUIExampleTests/UIKitInteropTests.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ExampleApps/SwiftUIExample/SwiftUIExampleTests/UIKitInteropTests.swift b/ExampleApps/SwiftUIExample/SwiftUIExampleTests/UIKitInteropTests.swift index 198bc385c..b465cb36d 100644 --- a/ExampleApps/SwiftUIExample/SwiftUIExampleTests/UIKitInteropTests.swift +++ b/ExampleApps/SwiftUIExample/SwiftUIExampleTests/UIKitInteropTests.swift @@ -99,12 +99,14 @@ final class UIKitInteropTests: XCTestCase, View { func testPuttingAUIKitViewThatDoesNotTakeInDataInsideASwiftUIWorkflow() async throws { final class FR1: UIWorkflowItem, FlowRepresentable { + let nextButtonTag = UUID().hashValue @objc private func nextPressed() { proceedInWorkflow() } override func viewDidLoad() { let nextButton = UIButton() + nextButton.tag = nextButtonTag nextButton.setTitle("Next", for: .normal) nextButton.setTitleColor(.systemBlue, for: .normal) nextButton.addTarget(self, action: #selector(nextPressed), for: .touchUpInside) @@ -142,7 +144,7 @@ final class UIKitInteropTests: XCTestCase, View { proceedCalled.fulfill() } - let nextButton = try XCTUnwrap(vc.view.subviews.first { $0 is UIButton } as? UIButton) + let nextButton = try XCTUnwrap(vc.view.viewWithTag(vc.nextButtonTag) as? UIButton) XCTAssertEqual(nextButton.willRespondToUser, true) nextButton.simulateTouch() From fc4a017fb9c5b3bd2aeac7657e66fda7f70a019b Mon Sep 17 00:00:00 2001 From: Richard Gist Date: Sat, 5 Nov 2022 08:38:55 -0600 Subject: [PATCH 3/4] Adding back removed new line --- .../SwiftUIExample/SwiftUIExampleTests/UIKitInteropTests.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/ExampleApps/SwiftUIExample/SwiftUIExampleTests/UIKitInteropTests.swift b/ExampleApps/SwiftUIExample/SwiftUIExampleTests/UIKitInteropTests.swift index b465cb36d..4c4f27e42 100644 --- a/ExampleApps/SwiftUIExample/SwiftUIExampleTests/UIKitInteropTests.swift +++ b/ExampleApps/SwiftUIExample/SwiftUIExampleTests/UIKitInteropTests.swift @@ -100,6 +100,7 @@ final class UIKitInteropTests: XCTestCase, View { func testPuttingAUIKitViewThatDoesNotTakeInDataInsideASwiftUIWorkflow() async throws { final class FR1: UIWorkflowItem, FlowRepresentable { let nextButtonTag = UUID().hashValue + @objc private func nextPressed() { proceedInWorkflow() } From 6cc9b802bc296c4311c21d42314439e681a6da7a Mon Sep 17 00:00:00 2001 From: Richard Gist Date: Sat, 5 Nov 2022 08:40:58 -0600 Subject: [PATCH 4/4] VSCode in GitHub was lying about whitespace --- .../SwiftUIExample/SwiftUIExampleTests/UIKitInteropTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ExampleApps/SwiftUIExample/SwiftUIExampleTests/UIKitInteropTests.swift b/ExampleApps/SwiftUIExample/SwiftUIExampleTests/UIKitInteropTests.swift index 4c4f27e42..850f67cb1 100644 --- a/ExampleApps/SwiftUIExample/SwiftUIExampleTests/UIKitInteropTests.swift +++ b/ExampleApps/SwiftUIExample/SwiftUIExampleTests/UIKitInteropTests.swift @@ -100,7 +100,7 @@ final class UIKitInteropTests: XCTestCase, View { func testPuttingAUIKitViewThatDoesNotTakeInDataInsideASwiftUIWorkflow() async throws { final class FR1: UIWorkflowItem, FlowRepresentable { let nextButtonTag = UUID().hashValue - + @objc private func nextPressed() { proceedInWorkflow() }