Chengxin University 807 Program Comprehensive Design 2015-2022 Real Questions and Answers [Continuous Update]

2022-12-28   ES  

1. Dynamic to add method to NSObject

@interface NSObject (CategoryWithProperty)

@property (nonatomic, strong) NSObject *property;

@end

@implementation NSObject (CategoryWithProperty)

– (NSObject *)property {

return objc_getAssociatedObject(self, _cmd);

}

– (void)setProperty:(NSObject *)value {

objc_setAssociatedObject(self, @selector(property), value, OBJC_ASSOCIATION_RETAIN_NONATOMIC);

}

2. Dynamic extension attributes

#import “UILabel+Associate.h”

#import <objc/runtime.h>

@implementation UILabel (Associate) static char flashColorKey;

– (void) setFlashColor:(UIColor *) flashColor{

objc_setAssociatedObject(self, &flashColorKey, flashColor, OBJC_ASSOCIATION_RETAIN_NONATOMIC);

}

– (UIColor *) getFlashColor{

return objc_getAssociatedObject(self, &flashColorKey);

}

@end

source

Related Posts

linux C Learn #include

GESTURE gesture notes

java multi -threaded ScheduledexecutorService

PYQT5 Chinese File Dialog box QFILEDIALOG The solution to collapse after calling

Chengxin University 807 Program Comprehensive Design 2015-2022 Real Questions and Answers [Continuous Update]

Random Posts

Deep Learning Deeplearning Recommended Paper List List of Princess Scholars Recommended Learning route scoField

RTSP protocol video intelligent monitoring platform Easynvr uses mysql as a data source to start an error of the Unknow Driver “mysql”

How to judge whether an Activity is displayed at the top

OPENCV training classifier Make XML document

linux driver-symbol export Monkey