swift 添加属性
2016-03-24 22:18
399 查看
extension UIButton {
private struct AssociatedKeys {
static var indexPath:NSIndexPath?
}
var indexPath: NSIndexPath? {
get {
return objc_getAssociatedObject(self, &AssociatedKeys.indexPath) as? NSIndexPath
}
set {
if let newValue = newValue {
objc_setAssociatedObject(self, &AssociatedKeys.indexPath, newValue as NSIndexPath?, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}
}
}
private struct AssociatedKeys {
static var indexPath:NSIndexPath?
}
var indexPath: NSIndexPath? {
get {
return objc_getAssociatedObject(self, &AssociatedKeys.indexPath) as? NSIndexPath
}
set {
if let newValue = newValue {
objc_setAssociatedObject(self, &AssociatedKeys.indexPath, newValue as NSIndexPath?, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}
}
}
相关文章推荐
- swift 动态获取类, 获取命名空间
- swift学习入门笔记1
- Swift实现断点续传,Demo简单易懂,没有太多复杂模块和逻辑,完整体现断点续传的原理
- swift系统学习控件篇:UIbutton+UIlabel+UITextField+UISwitch+UISlider
- swift约束之SnapKit的使用方式
- Swift与C char*
- Swift 中 callback 调用
- Swift中C的Block的调用
- Swift-'as?','as'用法
- swift 单例
- swift switch
- Swift-'!','?'用法
- Swift-Debug下打印函数名和行数
- 自主学习之RxSwift(一) -----Driver
- 自主学习之RxSwift(一) -----Driver
- swift !?
- Swift语法
- swift2.2的新特性
- RxSwift:ReactiveX for Swift 翻译
- RxSwift:ReactiveX for Swift 翻译