问题描述
对于OSX Playground,我输入以下代码:
import Cocoa
PlayView: NSView {
override func drawRect(dirtyRect:NSRect){
let blue = NSColor.blueColor()
blue.setFill $ b NSRectFill(self.bounds)
}
}
var view = PlayView(frame:NSRect(x:0,y:0 ,width:200,height:200))
然后我得到这个输出:
Playground执行失败:< EXPR>:12:18:error:using undeclared type'NSView'
/ pre>
class PlayView:NSView {
^ ~~~~~
< EXPR>:14:39:错误:使用未声明的类型'NSRect'
override func drawRect(dirtyRect:NSRect){
^ ~~~~~
< EXPR>:25:28:错误:使用未解析的标识符'NSRect'
var view = PlayView(frame:NSRect(x:0,y:0,width: 200,height:200))
^
< EXPR>:16:20:error:使用未解析的标识符'NSColor'
let blue = NSColor.blueColor ^
< EXPR>:19:9:错误:使用未解析的标识符'NSRectFill'
NSRectFill(self.bounds)
^
这个代码在一个大的Playground崩溃之前工作,但现在它完全死了,因为没有一个Cocoa类被导入,但我已经导入Cocoa并确保
我也可以在iOS配置的操场中创建一个iOS对等体,它可以正常工作但是OSX版本已经破坏。
有任何想法吗?
解决方案Per Matt的建议(),我一次通过他的列表一次(每次重新启动XCode),当我删除/ var /
编辑:
这种情况对我来说经常在操场上做很多,我一直在使用:这解决了它
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?
解决方案Per Matt's suggestion (http://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:
and that's solved it
这篇关于未声明在游乐场类型'NSView'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!