1

There is this post re: passing data between view controllers:

Passing Data between View Controllers

I don't think what i'm after is on there.

In ViewController 1 I load async data from firebase and i'd like to go to ViewController 2 without waiting for VC 1 to return all the data.

On VC2 there is a button that I want disabled until VC 1 has finished.

I did try setting a property in my singleton to true when the data has finished loading and then in VC2 looping until this property returned true but it appears once I have segued from VC1 then it won't set the property in my singleton to true in the background.

Thx.

Mike
  • 1,281
  • 3
  • 14
  • 41

1 Answers1

1

Of course there are many solutions, you might try to use the NotificationCenter, doing something like:

// in VC2: let's start listening for VC1 callback
NotificationCenter.default.addObserver(self, selector: #selector(self.callbackFromVC1(_:)), name: Notification.Name("VC1HasFinished"), object: nil)

// in VC2: this is the callback will be executed
func callbackFromVC1(_ notification: NSNotification? = nil) {
  let userInfoFromVC1:[AnyHashable : Any]? = notification?.userInfo
  // do something with userInfoFromVC1
}

....

// in VC1: when your async stuff is finished, push "userInfoFromVC1" into the notification...
NotificationCenter.default.post(name: NSNotification.Name.init(rawValue: "VC1HasFinished"), object: nil, userInfo:userInfoFromVC1)
mugx
  • 9,869
  • 3
  • 43
  • 55