您的位置:首页 > 移动开发 > Swift

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)

            }

        }

    }

    

    

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: