From 270ac1a4d53825bb57eed54ae26041e2c323ff2d Mon Sep 17 00:00:00 2001 From: Nikita Semenov Date: Fri, 31 Mar 2023 10:19:45 +0300 Subject: [PATCH] fix: code review notes --- README.md | 1 + .../BaseNavigationStackDeeplinkHandler.swift | 7 +-- .../UIViewController+DeeplinkHandler.swift | 3 -- .../Deeplinks.xcplaygroundpage/Contents.swift | 13 +---- .../Sources/NefTest.swift | 47 ------------------- 5 files changed, 7 insertions(+), 64 deletions(-) delete mode 100644 TIDeepLink/TIDeeplink.app/Contents/MacOS/TIDeeplink.playground/Sources/NefTest.swift diff --git a/README.md b/README.md index cce12647..30237366 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,7 @@ LICENSE - [TIUIElements](docs/tiuielements) * [Skeletons](docs/tiuielements/skeletons.md) * [Placeholders](docs/tiuielements/placeholder.md) +- [TIDeeplink](docs/tideeplink/deeplinks.md) - [Semantic Commit Messages](docs/semantic-commit-messages.md) - commit message codestyle. - [Snippets](docs/snippets.md) - useful commands and scripts for development. diff --git a/TIDeepLink/Sources/DeeplinkHandler/BaseNavigationStackDeeplinkHandler.swift b/TIDeepLink/Sources/DeeplinkHandler/BaseNavigationStackDeeplinkHandler.swift index ece0fd95..fed54d37 100644 --- a/TIDeepLink/Sources/DeeplinkHandler/BaseNavigationStackDeeplinkHandler.swift +++ b/TIDeepLink/Sources/DeeplinkHandler/BaseNavigationStackDeeplinkHandler.swift @@ -23,10 +23,11 @@ import Foundation import UIKit -open class BaseNavigationStackDeeplinkHandler: DeeplinkHandler { - public var rootViewControllerKeeper: RootViewController +open class BaseNavigationStackDeeplinkHandler: DeeplinkHandler { - public init(rootViewControllerKeeper: RootViewController) { + public var rootViewControllerKeeper: UIViewController + + public init(rootViewControllerKeeper: UIViewController) { self.rootViewControllerKeeper = rootViewControllerKeeper } // MARK: - DeeplinkHandler diff --git a/TIDeepLink/Sources/DeeplinkHandler/Helpers/UIViewController+DeeplinkHandler.swift b/TIDeepLink/Sources/DeeplinkHandler/Helpers/UIViewController+DeeplinkHandler.swift index 189f3ef9..9a6a1314 100644 --- a/TIDeepLink/Sources/DeeplinkHandler/Helpers/UIViewController+DeeplinkHandler.swift +++ b/TIDeepLink/Sources/DeeplinkHandler/Helpers/UIViewController+DeeplinkHandler.swift @@ -22,11 +22,8 @@ import UIKit -public typealias DeeplinkHandlerViewController = DeeplinkHandler & UIViewController - public extension UIViewController { func findHandler(for deeplink: Deeplink) -> DeeplinkHandler? { - if let deeplinksHandler = self as? DeeplinkHandler, let _ = deeplinksHandler.handle(deeplink: deeplink) { return deeplinksHandler diff --git a/TIDeepLink/TIDeeplink.app/Contents/MacOS/TIDeeplink.playground/Pages/Deeplinks.xcplaygroundpage/Contents.swift b/TIDeepLink/TIDeeplink.app/Contents/MacOS/TIDeeplink.playground/Pages/Deeplinks.xcplaygroundpage/Contents.swift index 847a0c53..8a801417 100644 --- a/TIDeepLink/TIDeeplink.app/Contents/MacOS/TIDeeplink.playground/Pages/Deeplinks.xcplaygroundpage/Contents.swift +++ b/TIDeepLink/TIDeeplink.app/Contents/MacOS/TIDeeplink.playground/Pages/Deeplinks.xcplaygroundpage/Contents.swift @@ -104,13 +104,6 @@ application(.shared, open: url) /*: В качестве `DeeplinkHandler` можно использовать базовую реализацию `BaseNavigationStackDeeplinkHandler`, которая позволяет искать handler в иерархии view, способный обработать диплинк */ -class NavigationController: UINavigationController, DeeplinkHandler { - - func handle(deeplink: Deeplink) -> Foundation.Operation? { - nil - } -} - class ViewController: UIViewController, DeeplinkHandler { func handle(deeplink: Deeplink) -> Operation? { if deeplink == .editProfile { @@ -130,11 +123,9 @@ class ViewController: UIViewController, DeeplinkHandler { } //: Создание Handler. Для настройки передается rootViewController, который должен наследоваться от `UIViewController` и соответствовать протоколу `DeeplinkHandler`. С этого контроллера будет начинаться поиск обработчика -typealias ProjectNavigationStackDeeplinkHandler = BaseNavigationStackDeeplinkHandler - let viewController = ViewController() -let navigationController = NavigationController(rootViewController: viewController) -let handler = ProjectNavigationStackDeeplinkHandler(rootViewControllerKeeper: navigationController) +let navigationController = UINavigationController(rootViewController: viewController) +let handler = BaseNavigationStackDeeplinkHandler(rootViewControllerKeeper: navigationController) //: Далее handler может передаваться для использования в `TIDeeplinksService` let service = TIDeeplinksService(mapper: mapper, handler: handler) diff --git a/TIDeepLink/TIDeeplink.app/Contents/MacOS/TIDeeplink.playground/Sources/NefTest.swift b/TIDeepLink/TIDeeplink.app/Contents/MacOS/TIDeeplink.playground/Sources/NefTest.swift deleted file mode 100644 index fe15078e..00000000 --- a/TIDeepLink/TIDeeplink.app/Contents/MacOS/TIDeeplink.playground/Sources/NefTest.swift +++ /dev/null @@ -1,47 +0,0 @@ -import Foundation -import XCTest - -public extension Nef { - - static func run(testCase class: T.Type) { - startTestObserver() - T.defaultTestSuite.run() - } - - static private func startTestObserver() { - _ = testObserverInstalled - } - - static private var testObserverInstalled = { () -> NefTestFailObserver in - let testObserver = NefTestFailObserver() - XCTestObservationCenter.shared.addTestObserver(testObserver) - return testObserver - }() -} - -// MARK: enrich the output for XCTest -fileprivate class NefTestFailObserver: NSObject, XCTestObservation { - - private var numberOfFailedTests = 0 - - func testSuiteWillStart(_ testSuite: XCTestSuite) { - numberOfFailedTests = 0 - } - - func testSuiteDidFinish(_ testSuite: XCTestSuite) { - if numberOfFailedTests > 0 { - print("💢 Test Suite '\(testSuite.name)' finished with \(numberOfFailedTests) failed \(numberOfFailedTests > 1 ? "tests" : "test").") - } else { - print("🔅 Test Suite '\(testSuite.name)' finished successfully.") - } - } - - func testCase(_ testCase: XCTestCase, - didFailWithDescription description: String, - inFile filePath: String?, - atLine lineNumber: Int) { - - numberOfFailedTests += 1 - print("❗️Test Fail '\(testCase.name)':\(UInt(lineNumber)): \(description.description)") - } -}