0

The picture is just an example...

enter image description here

So basically I want to pass data from RED to BLUE but i have to go through GREEN.. is there a way to just pass the data straight to BLUE without it having to go through GREEN?

What I'm doing now is the conventional method of passing the data to GREEN then having GREEN read it and pass it on to BLUE

But my app has a lot of ViewControllers and I wish to be able to pass it straight to the final page (BLUE page) is there a way? Sorry I'm new to the Swift

Mannopson
  • 2,634
  • 1
  • 16
  • 32
ducklol
  • 15
  • 1
  • 6

3 Answers3

1

If you try to pass data from _Red to _Blue, without _Green - it about bad architecture, becouse if something changed in logic of app, and you need to changed flow of controllers - you will feel a lot of headache...

You can wrap your data in object and pass through or you can make DataController which will be manage your data, and your ViewController's will be get\set it by Datacontroller interface

Daivest
  • 66
  • 4
0

Use a simple swift class e.g Sharedclass to set a variable and then get the value of the variable from the same Sharedclass. Example is given below

import Foundation

class SharedClass {
  static let sharedInstance = SharedClass()
  var phoneNumber = ""
}

To set the variable

SharedClass.sharedInstance.phoneNumber = "123456"

To get the variable

BLUEViewController.phoneNumber = SharedClass.sharedInstance.phoneNumber
Ganesh Kumar
  • 1,631
  • 2
  • 21
  • 35
0

You can push your navigationController directly to one of your viewControllers. Try this;

let storyboard = UIStoryboard(name: "Main", bundle: nil)
if let blueController = storyboard.instantiateViewController(withIdentifier: "BlueViewController") as? BluewViewController {
        blueController.passedData = passedData
        navigationController?.pushViewController(blueController, animated: true)
    }

Or you can just present it too. Instead of pushing in navigation controller.

let storyboard = UIStoryboard(name: "Main", bundle: nil)
if let blueController = storyboard.instantiateViewController(withIdentifier: "BlueViewController") as? BluewViewController {
        blueController.passedData = passedData
        present(blueController, animated: true, completion: nil)
    }
Unal Celik
  • 186
  • 3
  • 13
  • urmm but the app flow has to still be RED GREEN BLUE.. i just want to pass certain data from RED straight to BLUE.. – ducklol Feb 11 '17 at 09:38
  • Well, i don't think there is a straight way of doing this. Because views must be loaded for filling their properties. You can wrap your data in an object maybe. But views will still needs to be loaded. – Unal Celik Feb 11 '17 at 09:57