Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
objc runtime associate objects
//
// UIViewController+Extensions.h
//
// Created by thanhvu on 7/21/19.
// Copyright © 2019 thanhvu. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface UIViewController (Extensions)
@property (nonatomic, strong) NSString *screenName;
@end
NS_ASSUME_NONNULL_END
//
// UIViewController+Extensions.m
//
// Created by thanhvu on 7/21/19.
// Copyright © 2019 thanhvu. All rights reserved.
//
#import "UIViewController+Extensions.h"
#import <objc/runtime.h>
@implementation UIViewController (Extensions)
-(void)setScreenName:(NSString *)screenName
{
objc_setAssociatedObject(self, @selector(screenName), screenName, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
-(NSString *)screenName {
return objc_getAssociatedObject(self, @selector(screenName));
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment