iOS 如何给类别添加属性
2017-11-15 09:28
190 查看
.H 文件
.M 文件
#import <UIKit/UIKit.h> @interface UIViewController (statistics) @property (nonatomic, strong, readwrite) id myCustomProperty; @end
.M 文件
static void * myCustomCategoryPorpertyKey = (void *)@"myCustomCategoryPorpertyKey"; - (id)myCustomProperty { return objc_getAssociatedObject(self, myCustomCategoryPorpertyKey); } - (void)setMyCustomProperty:(id)myCustomProperty { objc_setAssociatedObject(self, myCustomCategoryPorpertyKey, myCustomProperty, OBJC_ASSOCIATION_RETAIN_NONATOMIC); }
相关文章推荐
- 如何给iOS 分类添加 属性
- iOS通过rumtime给类别添加动态属性
- iOS 给类别里面添加属性
- iOS学习之利用关联对象让类别有添加属性效果
- iOS类别(category)不能添加成员变量但是可以添加属性的问题
- iOS - 如何给1个类添加属性
- iOS Runtime应用实例(一)类别添加属性
- iOS 类别 ---不能添加属性
- ios-给AttributedString添加属性以及如何去取
- iOS为类别添加属性的方法(RunTime)
- iOS开发---如何给类别增加属性
- IOS在类别中添加属性
- 如何在类别中添加属性
- ios类别(category)不能添加成员变量但是可以添加属性的问题
- iOS 给类别(Category)添加weak (property)属性,关联(Associated)
- IOS类别通过关联对象添加属性
- 如何添加网站产品类别+网站产品的添加
- iOS 利用运行时机制给现有类添加属性
- 如何应用autosizing属性使iOS应用程序界面适配iPhone5
- 自己解决如何获取在DropDownList中添加的自定义属性的值