Last active
July 21, 2019 08:53
-
-
Save vikage/8b02fa904cb5630a1d0f55a605fdf411 to your computer and use it in GitHub Desktop.
objc runtime associate objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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