how to pass data between two view controller that separated by UITabBarController?

swift passing data between view controllers programmatically
pass data between view controllers swift without segue
how to pass data from second view controller to first view controller in swift
pass data between tab bar view controllers swift 4
how to pass data from one viewcontroller to another view controller
passing data between view controllers using delegates in swift 4
pass data between view controllers (swift with segue)
passing data from tableview to viewcontroller swift 4

I want to pass User Data (object) from LoginVC to HomeVC, but between those two view controllers, it is separated by UITabBarController and NavigationController like the Image below:

I want to pass User Data from this loginVC. from this loginVC, it will push segue to main.storyboard like the image below

here is the main.storyboard that contains tab bar controller, in the first tab bar (index = 0) is where the HomeVC located, I put the homeVC in the Home.storyboard

and here is the Home.storyboard, there is Navigation controller before I finally reach the HomeVC.

so how to pass data from LoginVC to HomeVC? it seems that I have to pass data from: LoginVC -> TabBarController -> NavigationController -> HomeVC

what should I do ?

the User data is like the code below:

struct User {
    var username : String
    var firstName: String
    var lastName: String
    var userCode : String
    var address: String
    var phoneNumber: String
    var dateOfBirth: String
    var outlet : Outlet // custom object

    init (dictionary: [String:Any]) {
        username = dictionary["user_name"] as? String ?? ""
        firstName = dictionary["customers_firstname"] as? String ?? ""
        lastName = dictionary["customers_lastname"] as? String ?? ""
        userCode = dictionary["kode_customer"] as? String ?? ""
        address = dictionary["alamat_user"] as? String ?? ""
        phoneNumber = dictionary["customers_telephone"] as? String ?? ""
        dateOfBirth = dictionary["customers_dob"] as? String ?? ""
        outlet = Outlet(dictionary: dictionary)


UITabBarController maintains the array of view controller, in order of tab index.

And again same way UINavigationController also maintains the controller stack.

so you just need to get the object of your view controller from the array (by type casting it) and pass the data.

Swift Swift Tutorials: Passing Data in Tab Bar Controllers – Make , While you can delegate between view controllers in tab bar have independent view controllers with completely separate functions, 2. 3. 4. class OrderTabController: UITabBarController {. var myOrder = OrderModel(). }  Here’s how you pass data forward from view controller A to view controller B, with a property: First, create the property for the data on view controller B (the receiving view controller). In the above example, that’s text. Second, determine what happens with the data in view controller B.

User data is importment, you shall consider to save user data in local file, and then you can fetch user data everywhere.

Passing Data Between View Controllers in iOS: The Definitive Guide, While in those articles I treated view controller as separate independent entities, they are not. In any non-trivial app, view controllers need to  Passing data between view controllers inside a tab bar controller Another common container in iOS apps is the tab bar controller. This allows the user to switch between different tabs using a tab bar at the bottom of the screen.

UITabBarController class contain an array of ViewControllers.

You can access the first ViewContoller using normal indexing inside any of view controller inside the UITabBarController:


UIViewController, Instead, you often use multiple view controllers, each of which owns a portion of your app's user interface. Each view controller manages a view hierarchy, the root view of which is stored in the view Called when a split view controller transitions to a compact-width size class. var tabBarController: UITabBarController? In this video I am going to share with you how to switch between view controllers in UITabBarController. Other videos from this series you can find in my blo

How to pass data through TabBarCon…, I try to pass data from View Controller through Tab Bar Controller and Navigation @IBAction func addToCarButton(_ sender: UIButton) { tabBarController? SomeImage(photo: imageView.image!) } 2. Get data in Table View Controller. How to pass data between two ViewControllers with TabBarController in Swift. ios,swift,uitabbarcontroller,viewcontroller. The UIViewController that wants to pass the data can store it on your AppDelegate class. Then the UITabBarController delegate method can pull it off and set properties on the receiving UIViewController.

Passing Data between View Controllers (Swift 4), When your app has multiple User Interfaces, you'll want to move data from one UI to the next. How do you pass data between view controllers in Swift? The developers that work on separate classes only need to agree on  [Updated for Swift 2.0/iOS9 9/21/15 SJL] While you can delegate between view controllers in tab bar controllers, it's debatable if you want to. Tab bar controllers can break down MVC in cases. On one hand Apps with tab bar controllers have independent view controllers with completely separate functions, much like Apple's clock app. Though the…

Pass Data Between View Controllers – LearnAppMaking, And you want to pass data backward to the previous view controller? to accomplish the task of passing data back when you dismiss a view controller. You can certainly separate these two functions into two protocols: Or indirectly through navigationController , splitViewController , or tabBarController . If you have a value in one view controller and want to pass it to another, there are two approaches: for passing data forward you should communicate using properties, and for passing data backwards you can either use a delegate or a block. Passing data forward is used when you want to show some information in a detail view controller.

  • how you are navigating to LoginVC to mainTabbarVC can you post the code
  • Instead of passing User data from multiple controller, store User data in UserDefault and access those data in controller where you want.