Last active
July 21, 2019 09:08
-
-
Save vikage/18b510a77e26a1a59cd3a31a8dc78f5d to your computer and use it in GitHub Desktop.
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
// | |
// 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 |
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
// | |
// 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