我已将globalUser定义为A.swift文件中的全局变量。如何在B.swift中观察globalUser的变化。
// 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
}
}
````
答案 0 :(得分:0)
将globalUser包装在MutableProperty中并观察:
// 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
}
}