类扩展, 为类添加属性
- 如代码所示, 创建属性, 并实现set和get方法
- 利用OC的runtime特性
private var kHJRefreshHeaderKey: String = ""
/// header
var hj_header: HJRefreshHeaderView? {
get {
return (objc_getAssociatedObject(self, &kHJRefreshHeaderKey) as? HJRefreshHeaderView)
}
set(newValue) {
objc_setAssociatedObject(self, &kHJRefreshHeaderKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN)
}
}