-1

I have UITabViewController and two UIViewControllers. I use storyboards and segues. In the first VC. I get data from Firebase and save it. Then I need to pass this data to another vc in order to change the text of UILabel in the second vc. Thank you

func fetchCeloriesData() {
        refWorkout = workout!.title
         Database.database().reference().child("programs").child(refWorkout).child("calories").observeSingleEvent(of: .value) { (snapshot) in
            let caloriesData = snapshot.value as! String
            print(caloriesData)
            
           
           // self.dietVC.BurnedLabel.text? = caloriesData
             
         }
     }
Rozgen
  • 47
  • 7
  • I'm not sure it's the best way, but for simple data like Int/String I use Userdefaults, while for objects I call in the VC where I want the data to be passed something like: VC1().dataINeedToPass and I assign it to a new variable – Federica Benacquista Dec 16 '20 at 09:14
  • If I don't misunderstand, this might be what you want -> [How to pass data to UITabBarController](https://stackoverflow.com/a/44180862/11593936) – Alice S. Dec 16 '20 at 09:44

1 Answers1

0

If you are using storyboards and segues, you can simply use

func prepare(for segue: UIStoryboardSegue, 
  sender: Any?)

you can identify segue there from storyboard and sender will be self. and then

func performSegue(withIdentifier identifier: String, 
       sender: Any?)

Here you have to take identifier from storyboard which will be string. and on the event of moving to second ViewController call this perfromSegue function.