我想在 UITextView
的扩展中添加闭包属性,所以我使用 typealias 定义了一个闭包:
typealias TextViewHeightDidChangedClosure = (_ currentTextViewHeight:CGFloat)->Void
extension UITextView{
func setTextViewHeightDidChanged(textViewHeightDidChanged:TextViewHeightDidChangedBlock){
objc_setAssociatedObject(self, &TextViewHeightDidChangedBlockKey, textViewHeightDidChanged, objc_AssociationPolicy.OBJC_ASSOCIATION_COPY_NONATOMIC)
}
func textViewHeightDidChanged()->TextViewHeightDidChangedBlock?{
let textChanged : ((CGFloat)->Void) = objc_getAssociatedObject(self, &TextViewHeightDidChangedBlockKey) as! TextViewHeightDidChangedBlock
return textChanged
}
}
但它告诉我一个错误:
Command failed due to signal: Segmentation fault: 11.
这是错误的图片
谁能告诉我为什么并给我一个深刻有意义的解释,非常感谢!
最佳答案
如果您在类中声明 Bool!
属性并尝试使用此属性创建三元条件,您也可能会遇到此错误:
var isSomething: Bool!
func myFunc() {
let value = isSomething ? "something" : "not"
}
只需添加 !在您的属性(property)上
var isSomething: Bool!
func myFunc() {
let value = isSomething! ? "something" : "not"
}
关于swift - 命令因信号 : Segmentation fault: 11 while emitting IR SIL function 而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40968517/