如何在 Swift Playground 中使用`SELF`?

问题描述 投票:0回答:1

如何引用 Swift Playground 本身?

我正在尝试使用

NSNotificationCenter
来观察某些变量,但我不知道如何在
Playground
上实现它。

这是我的代码。我只想观察

timeout
变量,但没有
willSet
方法。

var timeout = false
var cont: Int8 = 1

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

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

swift swift-playground observers
1个回答
2
投票

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

或者您可能对此感兴趣: 如何引用 Swift Playground 本身?

© www.soinside.com 2019 - 2024. All rights reserved.