Search code examples
iosuiviewswiftswift-extensions

A bug ? Property in an extension of UIView


I created an extension for the UIView:

import UIKit

extension UIView {

    var frameHeight : CGFloat {

        get {
            return self.frame.size.height
        }
        set(newHeight) {
            self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y,self.frame.size.width, newHeight)
        }
    }
}

Then I used this inside the method of my own UIView:

class MyView: UIView {

   func updateHeight() {

        self.frameHeight = 200.0
        setNeedsDisplay()
    }
}

I got a compile error:

While emitting IR SIL function @_TFC15Simple15MyView10updateHeightfS0_FT_T_ for 'updateHeight' at /MyView.swift:88:5
<unknown>:0: error: unable to execute command: Segmentation fault: 11
<unknown>:0: error: swift frontend command failed due to signal (use -v to see invocation)
Command /Applications/Xcode6-Beta3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift failed with exit code 254

When I comment out the line self.frameHeight = 200.0, the compile error is gone.

Is it a bug? Or did I do something wrong? Thanks.


Solution

  • It works when I run it in a Playground and I don't see anything obviously wrong.

    In any case, even if it is a bug in your code, it shouldn't crash the compiler. I think you should create a bug report with Apple.