-1

I have defined globalUser as a global variable in A.swift file. How to observe globalUser's changes in B.swift.

// A.swift
var globalUser: Dictionary<String, Any?>? = nil


// B.swift
class MeViewController: UITableViewController {
    var user: Dictionary<String, Any?>?

    override func viewDidLoad() {
        super.viewDidLoad()
        // how to bind user with globalUser using ReactiveCocoa? Or Observing globalUser's changing, to update user
    }

}

````

ashoka
  • 1
  • Please check [how to ask question](https://stackoverflow.com/help/how-to-ask) [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – Morse Mar 29 '18 at 14:46

1 Answers1

0

wrap the globalUser in a MutableProperty and observe that:

// A.swift
let globalUser: MutableProperty<[String: Any]?> = MutableProperty(nil)

// B.swift
class MeViewController: UITableViewController {
    var user: [String, Any]?

    override func viewDidLoad() {
        super.viewDidLoad()
        reactive[\.user] <~ globalUser
    }
}
ashoka
  • 1