I am trying to use dependency injection instead of following singletons. This is how I am trying to achieve. When I run the application I am having an error on "No "decodeObject" candidates produce the expected contextual result type "ModelManager"
on that. Any idea how can I implement dependency injection in a right way?
My Model class:
class ModelManager {
var results: MyCustomClass
init(results: MyCustomClass) {
self.results = results
}
func update(customDataInfo: MyCustomClass!) {
self.results = customDataInfo
}
}
MyViewController.swift
class MyViewController: UIViewController {
private let modelManager: ModelManager
init(modelManager: ModelManager) {
self.modelManager = modelManager
super.init(nibName: nil, bundle: nil)
self.modelManager.modelManagerUpdate = self as ModelManagerUpdate
}
required init?(coder aDecoder: NSCoder) {
self. modelManager = aDecoder.decodeObject(value(forKey: "modelManager") as ModelManager)
super.init(coder: aDecoder)
fatalError("init(coder:) has not been implemented")
}
override func encode(with aCoder: NSCoder) {
super.encode(with: aCoder)
aCoder.encode(self. modelManager, forKey: "modelManager")
}
}