From e20b3755999364cf8c03b1a8cbd8f6e62b1a8490 Mon Sep 17 00:00:00 2001 From: ekaterina-dv Date: Fri, 30 Jul 2021 14:38:38 +0200 Subject: [PATCH 1/2] draft --- Sources/Voiper/Embeddable.swift | 13 +++++++++++++ Sources/Voiper/VOIPER.swift | 12 ++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 Sources/Voiper/Embeddable.swift diff --git a/Sources/Voiper/Embeddable.swift b/Sources/Voiper/Embeddable.swift new file mode 100644 index 0000000..d0ed64f --- /dev/null +++ b/Sources/Voiper/Embeddable.swift @@ -0,0 +1,13 @@ +// +// File.swift +// +// +// Created by Ekaterina Dvuzhilova on 2021-07-30. +// + +import Foundation + +public protocol Embeddable { + associatedtype ParentControllable + +} diff --git a/Sources/Voiper/VOIPER.swift b/Sources/Voiper/VOIPER.swift index 47df33d..531812f 100644 --- a/Sources/Voiper/VOIPER.swift +++ b/Sources/Voiper/VOIPER.swift @@ -111,3 +111,15 @@ extension Organiser where Presenter.Configuration == Void, Interactor.Configurat router: Router.init(configuration: ())) } } + +extension Organiser where Presenter: Embeddable, ViewController: ViewControllerType { + public static func createAsChildModule(presenterConfiguration: Presenter.Configuration, interactorConfiguration: Interactor.Configuration, routerConfiguration: Router.Configuration) -> (UIViewController, Presenter.ParentControllable) { + let vc = wireUpModule(presenter: Presenter(configuration: presenterConfiguration), + interactor: Interactor(configuration: interactorConfiguration), + router: Router(configuration: routerConfiguration)) + guard let parentControllable = vc.presenter as? Presenter.ParentControllable else { + fatalError("") + } + return (vc, parentControllable) + } +} From 48fca9d926a92ef3598bf3328ab16a16931380bd Mon Sep 17 00:00:00 2001 From: ekaterina-dv Date: Fri, 30 Jul 2021 16:46:37 +0200 Subject: [PATCH 2/2] Minor code improvements --- Sources/Voiper/Embeddable.swift | 1 - Sources/Voiper/VOIPER.swift | 26 +++++++++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Sources/Voiper/Embeddable.swift b/Sources/Voiper/Embeddable.swift index d0ed64f..591f9d3 100644 --- a/Sources/Voiper/Embeddable.swift +++ b/Sources/Voiper/Embeddable.swift @@ -9,5 +9,4 @@ import Foundation public protocol Embeddable { associatedtype ParentControllable - } diff --git a/Sources/Voiper/VOIPER.swift b/Sources/Voiper/VOIPER.swift index 531812f..70d3eb5 100644 --- a/Sources/Voiper/VOIPER.swift +++ b/Sources/Voiper/VOIPER.swift @@ -114,12 +114,28 @@ extension Organiser where Presenter.Configuration == Void, Interactor.Configurat extension Organiser where Presenter: Embeddable, ViewController: ViewControllerType { public static func createAsChildModule(presenterConfiguration: Presenter.Configuration, interactorConfiguration: Interactor.Configuration, routerConfiguration: Router.Configuration) -> (UIViewController, Presenter.ParentControllable) { - let vc = wireUpModule(presenter: Presenter(configuration: presenterConfiguration), - interactor: Interactor(configuration: interactorConfiguration), - router: Router(configuration: routerConfiguration)) - guard let parentControllable = vc.presenter as? Presenter.ParentControllable else { + let childViewController = wireUpModule(presenter: Presenter(configuration: presenterConfiguration), + interactor: Interactor(configuration: interactorConfiguration), + router: Router(configuration: routerConfiguration)) + guard let parentControllable = childViewController.presenter as? Presenter.ParentControllable else { + // TODO: it should be fixed, we should think about how to handle it in the best way + // make optional or throw error or smth else? fatalError("") } - return (vc, parentControllable) + return (childViewController, parentControllable) + } +} + +extension Organiser where Presenter: Embeddable, ViewController: ViewControllerType, Presenter.Configuration == Void, Interactor.Configuration == Void, Router.Configuration == Void { + public static func createAsChildModule(presenterConfiguration: Presenter.Configuration, interactorConfiguration: Interactor.Configuration, routerConfiguration: Router.Configuration) -> (UIViewController, Presenter.ParentControllable) { + let childViewController = wireUpModule(presenter: Presenter(configuration: ()), + interactor: Interactor(configuration: ()), + router: Router(configuration: ())) + guard let parentControllable = childViewController.presenter as? Presenter.ParentControllable else { + // TODO: it should be fixed, we should think about how to handle it in the best way + // make optional or throw error or smth else? + fatalError("") + } + return (childViewController, parentControllable) } }