如何在 swift playground 中使用 `SELF`?

How to use `SELF` in swift playground?

如何引用Swift游乐场本身?

我正在尝试使用 NSNotificationCenter 来观察一些变量,但我不知道如何在 Playground 上实现它。

这是我的代码,实际上我只想观察 timeout 变量,但没有 willSet 方法。

var timeout = false
var cont: Int8 = 1

NSNotificationCenter.defaultCenter().addObserver(self, forKeyPath: timeout, options: NSKeyValueObservingOptions.New, context: &cont)

有什么办法可以在操场上做吗?

gitHub 上有 KVO playground,试试这个 https://github.com/rectalogic/KVOPlayground

或者您可能对此感兴趣: How to reference Swift Playground itself?