如何在快速操场上使用`SELF`?

时间:2016-05-02 06:28:02

标签: swift swift-playground observers

如何引用Swift Playground本身?

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

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

var timeout = false
var cont: Int8 = 1

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

有没有办法在操场上做?

1 个答案:

答案 0 :(得分:2)

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

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