Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coordinator Model Support #2

Open
brcbydr opened this issue May 12, 2020 · 0 comments
Open

Coordinator Model Support #2

brcbydr opened this issue May 12, 2020 · 0 comments

Comments

@brcbydr
Copy link

brcbydr commented May 12, 2020

Hi,

Thanks for the MVC example and the sliders.

I want to create model at first in AppCoordinator and don't want to get instance whole project. I don't know if this is the best way but I need my updated model in all the view controllers.

My code is like below, router is assigning, but model is still nil in VC? Why?

`class AppCoordinator {
var root: Presentable?
private var person: Person

init() {
    self.person = Person()
}

func start(in window: UIWindow) {
    root = {
        if MyUserDefaults.firstLaunch { //Uygulamaya ilk kez giriş yapılmışsa
            return GuideCoordinator(model: person)
        } else if FirestoreHandler.authUID == nil { //Daha önce giriş yapılmış ancak user authenticated değilse
            return AuthCoordinator(model: person)
        } else { //Daha önce giriş yapılmışsa ve kullanıcı authenticated ise
            return AuthCoordinator(model: person) //TODO: MainCoordinator()
        }
    }()
    root?.setRoot(for: window)
}

}

class AuthCoordinator: NavigationCoordinator {
private let disposeBag = DisposeBag()
private var person: Person

// MARK: Initialization
init(model: Person) {
    self.person = model
    super.init(initialRoute: .signInOrSignUp)
}

// MARK: Overrides
override func prepareTransition(for route: AuthRoute) -> NavigationTransition {
    switch route {
    case .signInOrSignUp:
        let vc = LoginRegisterViewController.instantiate()
        vc.router = unownedRouter
        vc.model = person
        vc.hideNavigationBar()
        return .push(vc) 
    }
}

}`

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant