Undeclared Type 'NSView' in Playground

99封情书 提交于 2019-12-22 12:27:41

问题


For an OSX Playground I enter the following code:

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))

I then get this output:

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)
        ^

This code was working before a big Playground crash but now it completely dies as if none of the Cocoa classes are being imported but I've imported Cocoa and made sure the playground is set for OSX.

I also can create an iOS equivalent in an iOS configured playground and it works fine but the OSX version is broken.

Any ideas?


回答1:


Per Matt's suggestion (https://stackoverflow.com/a/6247073/341994), I worked through his list one at a time (restarting XCode each time) and when I deleted the contents of /var/folders it began working again.

Edit: As this happens for me quite frequently when doing a lot in playgrounds, I've been using:

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

and that's solved it




回答2:


Seems to be working just fine.

Maybe just try it with a new playground document?



来源:https://stackoverflow.com/questions/26832794/undeclared-type-nsview-in-playground

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!