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!

Accepted Reply

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".

Replies

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

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".