1

我对 NSView 做了这个扩展,以便更轻松地使用视图。

import Cocoa

public extension NSView {
    var invertedFrame: NSRect {
    get {
        return NSRect(x: frame.origin.x,
                      y: superview.bounds.height - frame.origin.y,
                  width: bounds.size.width,
                 height: bounds.size.height)
    }
    set {

        self.frame = NSRect(x: newValue.origin.x,
                            y: superview.bounds.height - newValue.origin.y - newValue.height,
                        width: newValue.width,
                       height: newValue.height)
    }
    }
}

但是每当我尝试使用它时,我都会收到编译时错误...

Command /Applications/Xcode6-Beta4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift failed with exit code 254

但是,如果我将计算变量剪切并粘贴到类实现中,它就可以正常工作。

我不确定这是为什么。我的代码有问题吗?任何人都可以完成这项工作吗?

4

2 回答 2

0

您的属性设置器没有声明newValue为方法参数,而是没有告诉您,编译器显然崩溃了。请记住,set仅在protocol属性声明中才能找到裸露。

于 2014-08-03T19:35:09.707 回答
0

我不确定哪个更新解决了这个问题,但在 Xcode 6 beta 5 中它可以正常工作。所以这只是一个编译器错误。

于 2014-08-11T19:06:55.483 回答