MacOS Playground:如何更改背景颜色?

MacOS Playground: How can change the background color?

我正在尝试更改主视图的背景颜色:

import AppKit
import PlaygroundSupport

class ViewController : NSViewController {
    override func loadView() {
        let nibFile = NSNib.Name("MyView")
        var topLevelObjects : NSArray?
        Bundle.main.loadNibNamed(
            nibFile, owner:nil, topLevelObjects: &topLevelObjects)
        let views = (topLevelObjects as! Array<Any>).filter { [=10=] is NSView }
        self.view = views[0] as! NSView
        self.view.layer?.backgroundColor = NSColor.white.cgColor
    }
}

PlaygroundPage.current.liveView = ViewController()

但是视图没有改变颜色:

还有 "Hello world" 标签的来源?

非常感谢你的帮助

您只需将视图 wantsLayer 属性 设置为 true

let view = views[0] as! NSView
view.wantsLayer = true
view.layer?.backgroundColor = NSColor.blue.cgColor