Skip to content

Instantly share code, notes, and snippets.

@vikage
Last active July 21, 2019 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vikage/18b510a77e26a1a59cd3a31a8dc78f5d to your computer and use it in GitHub Desktop.
Save vikage/18b510a77e26a1a59cd3a31a8dc78f5d to your computer and use it in GitHub Desktop.
//
// 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