Playground 中未声明的类型“NSView”

2024-06-22

对于 OSX Playground,我输入以下代码:

import Cocoa

class PlayView : NSView {

    override func drawRect(dirtyRect: NSRect) {

        let blue = NSColor.blueColor()

        blue.setFill()
        NSRectFill(self.bounds)

    }
}


var view = PlayView(frame: NSRect(x: 0, y: 0, width: 200, height: 200))

然后我得到这个输出:

Playground execution failed: <EXPR>:12:18: error: use of undeclared type 'NSView'
class PlayView : NSView {
                 ^~~~~~
<EXPR>:14:39: error: use of undeclared type 'NSRect'
    override func drawRect(dirtyRect: NSRect) {
                                      ^~~~~~
<EXPR>:25:28: error: use of unresolved identifier 'NSRect'
var view = PlayView(frame: NSRect(x: 0, y: 0, width: 200, height: 200))
                           ^
<EXPR>:16:20: error: use of unresolved identifier 'NSColor'
        let blue = NSColor.blueColor()
                   ^
<EXPR>:19:9: error: use of unresolved identifier 'NSRectFill'
        NSRectFill(self.bounds)
        ^

这段代码在 Playground 发生大崩溃之前是可以工作的,但现在它完全死掉了,就好像没有导入任何 Cocoa 类,但我已经导入了 Cocoa 并确保 Playground 是为 OSX 设置的。

我还可以在 iOS 配置的 Playground 中创建一个 iOS 等效项,它工作正常,但 OSX 版本已损坏。

有任何想法吗?


根据马特的建议(https://stackoverflow.com/a/6247073/341994 https://stackoverflow.com/a/6247073/341994),我一次浏览了他的列表(每次都重新启动 XCode),当我删除 /var/folders 的内容时,它又开始工作了。

编辑: 由于我在游乐场做很多事情时经常发生这种情况,因此我一直在使用:

rm -rf“$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache”

就这样解决了

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Playground 中未声明的类型“NSView” 的相关文章

随机推荐