[ad_1]
I’m making an attempt to construct an app completely with coding and no storyboard utilization. I’m making an attempt to make use of Coordinater sample right here. I’m making an attempt to set my preliminary controller with my view mannequin in init technique however I get solely a black display. Though the init and viewDidLoad code is executed however the display nonetheless stays black. Following is my Coordinator:
class AppCoordinator {
non-public let window: UIWindow
init(window: UIWindow) {
self.window = window
}
func begin() {
let viewController = ViewController(with: RestaurantListViewModel(restaurantService: RestaurantService()))
let navigationController = UINavigationController(rootViewController: viewController)
window.rootViewController = navigationController
window.makeKeyAndVisible()
}
}
ViewController:
class ViewController: UIViewController {
let disposeBag = DisposeBag()
non-public var viewModel: RestaurantListViewModel!
init(with viewModel: RestaurantListViewModel) {
self.viewModel = viewModel
tremendous.init(nibName: nil, bundle: nil)
}
public required init?(coder aDecoder: NSCoder) {
tremendous.init(coder: aDecoder)
self.viewModel = nil
}
override func viewDidLoad() {
tremendous.viewDidLoad()
view.backgroundColor = .blue
let service = RestaurantService()
service.fetchRestaurants().subscribe { eating places in
print(eating places)
}.disposed(by: disposeBag)
}
}
SceneDelegate:
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
var appCoordinator: AppCoordinator?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, choices connectionOptions: UIScene.ConnectionOptions) {
guard let scene = (scene as? UIWindowScene) else { return }
let window = UIWindow(windowScene: scene)
appCoordinator = AppCoordinator(window: window)
appCoordinator?.begin()
}
}
[ad_2]
