Passing Data between ViewController

Hello,

i want to pass Data between two View Controller which are not parent. There is no children.

This works but I need it without parent for non children ViewController: let passedData = (self.parent as! TabBarController).var

Thanks for Help!

Answered by Master3000 in 710097022

The problem was the ViewController Type and how he gets presented. If the ViewController gets presented Modally, you need to change "parent" with "self.presentingViewController".

I need it without parent for non children ViewController: let passedData = (self.parent as! TabBarController).var

I suppose you refer to solution given here: https://developer.apple.com/forums/thread/112706

In SwiftUI, you can use environmentObject.

If you need, a short tutorial here:

https://www.hackingwithswift.com/quick-start/swiftui/how-to-use-environmentobject-to-share-data-between-views

Accepted Answer

The problem was the ViewController Type and how he gets presented. If the ViewController gets presented Modally, you need to change "parent" with "self.presentingViewController".

Passing Data between ViewController
 
 
Q