QuickBirdEng / XCoordinator-Example

XCoordinator-Example serves as an MVVM-C example app for XCoordinator
https://github.com/quickbirdstudios/XCoordinator
MIT License
65 stars 14 forks source link

Passing Data With XCoordinator #11

Open brcbydr opened 4 years ago

brcbydr commented 4 years ago

Hi all,

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. This can any data by the way, I want to pass data using XCoordinator.

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!

milanhorvatovic commented 4 years ago

did you consider using dependency injection or context to transport that data across the application?