一个bug? UIView扩展中的属性

时间:2014-07-11 15:58:14

标签: ios uiview swift swift-extensions

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

然后我在我自己UIView的方法中使用了这个:

class MyView: UIView {

   func updateHeight() {

        self.frameHeight = 200.0
        setNeedsDisplay()
    }
}

我收到了编译错误:

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

当我注释掉行self.frameHeight = 200.0时,编译错误就消失了。

这是一个错误吗?或者我做错了什么?感谢。

2 个答案:

答案 0 :(得分:1)

当我在游乐场中运行时它起作用,我没有看到任何明显错误。

在任何情况下,即使 是代码中的错误,也不应该使编译器崩溃。我认为你应该create a bug report与Apple合作。

答案 1 :(得分:0)

您必须将func声明为mutating