【发布时间】:2017-07-23 13:25:14
【问题描述】:
我有一个带有动态 var“值”的 vc,我需要知道它何时在调用 cv 的闭包中发生更改。
目标vc:
@objc dynamic var value: String = ""
来源:
if let vc: TagButtonPopupViewController = sb.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier("TagPopupViewController")) as? TagButtonPopupViewController {
// configure vc
vc.value = sender.title
// observe
_ = vc.observe(\.value) { (tbvc, change) in
print("new string")
}
// present popup
presentViewController(vc, asPopoverRelativeTo: sender.bounds, of: sender, preferredEdge: NSRectEdge.maxY, behavior: NSPopover.Behavior.transient)
}
但永远不会调用“观察”。 任何想法如何在 Swift4 中“值”发生变化时在闭包中获得通知?
【问题讨论】:
标签: swift key-value-observing swift4