.h
@property (nonatomic, strong)CFNotificationComponent *notificationComponent;
.m
// 通知懒加载初始化
static void *NotificationComponentKey = &NotificationComponentKey;
- (CFNotificationComponent *)notificationComponent
{
id component = objc_getAssociatedObject(self, NotificationComponentKey);
// lazily create the KVOController
if (nil == component) {
component = [[CFNotificationComponent alloc] init];
self.notificationComponent = component;
}
return component;
}
- (void)setNotificationComponent:(CFNotificationComponent *)notificationComponent
{
objc_setAssociatedObject(self, NotificationComponentKey, notificationComponent, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
网友评论