分类与继承的区别:分类不能添加属性(可以通过两个方法添加)
.h文件中
@property (nonatomic,strong)CLLocationManager *locationManger;
.m文件中
(添加setter,getter方法)
#import <objc/runtime.h>
- (void)setLocationManger:(CLLocationManager *)locationManger {
returnobjc_setAssociatedObject(self,@selector(locationManger), locationManger,OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (CLLocationManager *)locationManger {
//_cmd 是当前方法的指针
returnobjc_getAssociatedObject(self,_cmd);
}