// | |
// UIStoryboard+Swizzling.h | |
// | |
// Created by thanhvu on 7/21/19. | |
// Copyright © 2019 thanhvu. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> | |
NS_ASSUME_NONNULL_BEGIN | |
@interface UIStoryboard (Swizzling) | |
- (UIViewController *)swizz_instantiateViewControllerWithIdentifier:(NSString *)identifier; | |
@end | |
NS_ASSUME_NONNULL_END |
// | |
// UIStoryboard+Swizzling.m | |
// | |
// Created by thanhvu on 7/21/19. | |
// Copyright © 2019 thanhvu. All rights reserved. | |
// | |
#import "UIStoryboard+Swizzling.h" | |
#import <objc/runtime.h> | |
@implementation UIStoryboard (Swizzling) | |
+(void)load | |
{ | |
// 1 | |
Method originMethod = class_getInstanceMethod([UIStoryboard class], @selector(instantiateViewControllerWithIdentifier:)); | |
Method swizzMethod = class_getInstanceMethod([UIStoryboard class], @selector(swizz_instantiateViewControllerWithIdentifier:)); | |
// 2 | |
method_exchangeImplementations(originMethod, swizzMethod); | |
} | |
-(UIViewController *)swizz_instantiateViewControllerWithIdentifier:(NSString *)identifier | |
{ | |
// Inject code | |
// 3 | |
return [self swizz_instantiateViewControllerWithIdentifier:identifier]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment