我想在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.
这是错误的图像
谁能告诉我为什么,给我一个深刻有意义的解释,非常感谢你!