123456789101112131415161718192021 |
- //
- // NSObject+ImpChange.m
- // assemble
- //
- // Created by apple on 2020/11/2.
- // Copyright © 2020 kingsunsoft. All rights reserved.
- //
- #import "NSObject+ImpChange.h"
- #import <objc/runtime.h>
- @implementation NSObject (ImpChange)
- + (void)SwizzlingMethod:(NSString *)systemMethodString systemClassString:(NSString *)systemClassString toSafeMethodString:(NSString *)safeMethodString targetClassString:(NSString *)targetClassString{
- //获取系统方法IMP
- Method sysMethod = class_getInstanceMethod(NSClassFromString(systemClassString), NSSelectorFromString(systemMethodString));
- //自定义方法的IMP
- Method safeMethod = class_getInstanceMethod(NSClassFromString(targetClassString), NSSelectorFromString(safeMethodString));
- //IMP相互交换,方法的实现也就互相交换了
- method_exchangeImplementations(safeMethod,sysMethod);
- }
- @end
|