Search code examples
swiftswift-extensions

I made a Swift extension to use frames like I would on iOS but Can't compile while using it


I made this extension to NSView to make it easier to work with views.

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)
    }
    }
}

But whenever I try to use it I get the compile time error ...

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

However if I cut and paste the computed variable into a class implementation it works fine.

I am not sure why this is. Is there something wrong with my code? Can anyone make this work?


Solution

  • I'm not sure which update fixed this, but in Xcode 6 beta 5 it works fine. So it was just a compiler bug.