2

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?

Playground Screen Capture

Jay
  • 4,480
  • 3
  • 25
  • 22
  • 1
    Try doing all the stuff I recommend here: http://stackoverflow.com/a/6247073/341994 (You can omit cleaning the simulators, as they are not involved) – matt Nov 10 '14 at 04:06

2 Answers2

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

Community
  • 1
  • 1
Jay
  • 4,480
  • 3
  • 25
  • 22
  • 1
    Yeah, I thought that would do it. There is clearly some major Swift stuff in that _/var/folders_ cache... – matt Nov 10 '14 at 04:28
  • 1
    By the way thanks for doing a systematic test and for reporting back. I have a funny feeling your experience could prove useful to others. – matt Nov 10 '14 at 04:29
  • Yeah I hope so! I've wasted a few hours today trying to figure this one out. – Jay Nov 10 '14 at 04:59
0

Seems to be working just fine.

enter image description here

Maybe just try it with a new playground document?

Mundi
  • 79,884
  • 17
  • 117
  • 140
  • Yeah, I've done that. It was working fine before but now refuses to work. I've restarted XCode, rebooted, etc. It was working before but now doesn't. Short of reinstalling XCode any other ideas on how I might fix this? The Reset Playground option is always greyed-out. – Jay Nov 10 '14 at 03:19