can someone help me pls ? I trying to start my app buy i have error in AppDelegate. So in my AppDelegate I created navigationController and xcode wants that i use init from TableVC but i cant. How to fix it ? Thanks
Here is the compile error I get
My code:
AppDelegate:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let viewController = TableVC(container: TableVC.Depencies) <- and there i have error "Editor placeholder in source file" , i guess xcode wants init from tableVC
self.naviController = UINavigationController(rootViewController: viewController)
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = self.naviController
self.window?.backgroundColor = UIColor.white
self.window?.makeKeyAndVisible()
return true
}
TableVC:
typealias Depencies = ProtocolCoreData & APIService
private let jsonTask: APIService
private var cityTemps: [WeatherModel] = []
private let coreDataManaer: ProtocolCoreData
init(container: Depencies) {
self.jsonTask = container.apiService as APIService
self.coreDataManaer = container.coreDataService as ProtocolCoreData
super.init(nibName: nil, bundle: nil)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
2
Answers
You are passing the type "TableVC.Depencies" and not an instance of it.
…
and pass it to the viewController
Your
init
requires a type that conforms toProtocolCoreData & APIService
which I believe are protocols ?You can try the following options:
1 – You can create an empty init if you do not want to pass the dependency on init.
Then you need some kind of
type
which matches yourTableVC.Dependancy
profile, for exampleYou need to then initialize this type and pass this to your TableVC initializer
This should remove the compilation error