I am new to Clean VIP Architecture and I am struggling with its entry point.
(I am only putting some bit of code)
ViewController
protocol Delegate: class {
func execute()
}
class TitlesViewController:UIViewController {
weak var delegate: Delegate?
func viewDidLoad() {
super.viewDidLoad()
delegate.execute()
}
}
Configurator
class TitlesConfigurator {
static func configureModule(viewController: TitlesViewController) {
let interactor = Interaction()
viewController.delegate = interactor
}
}
In AppDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let titlesViewController = TitlesViewController()
let navigationController = UINavigationController(rootViewController: titlesViewController)
TitlesConfigurator.configureModule(viewController: titlesViewController)
window = UIWindow()
window?.rootViewController = navigationController
window?.makeKeyAndVisible()
return true
}
Now Issue that I am facing is that there is no reference of interactor
outside of TilesConfigurator
and delegate
is weak
which means its total arc
is 0. It results in delegate = nil
inside viewDidLoad
How can I improve or fix this issue in my architecture.
P.S: I don't think its good practice to make a strong reference of delegate inside ViewController
Delegate shouldn't be weak
here
var delegate: Delegate?
As there is one part that's weak
which is let interactor = Interaction()
so no retain cycles will occur