如何从游乐场中的笔尖获取视图?

How do you obtain a view from a nib within a playground?

在典型的 Xcode 项目中,您可以像这样从 nib 获取视图:

    var objects: NSArray?;
    NSBundle.mainBundle().loadNibNamed("ExampleView", owner: nil,
                                       topLevelObjects: &objects)
    var view :NSView
    for obj in objects! {
        if (obj.isMemberOfClass(NSView)) {
            view = obj as NSView
        }
    }
    // view is now the NSView object obtained from the nib. Yay.

但是,如果我在同一个 Xcode 项目中创建一个游乐场并尝试获取视图,则上述代码会失败。事实上,loadNibNamed:owner:topLevelObjects: returns false,我们知道加载nib失败了。

即使我创建了一个独立的游乐场,并将 .xib 文件放在 Resources 目录中,loadNibNamed:owner:topLevelObjects: 仍然 returns false。

为什么我不能使用 loadNibNamed:owner:topLevelObjects: 从 playground 访问 nib 文件?正确的做法是什么?

我犯的错误是将 .xib 而不是 .nib 放在资源目录中。一旦我将正确的文件(.nib 文件,durp)放入 Resources 目录,我确实可以访问该视图。