如何从混合调用原始方法?
[[UIWindow class] jr_swizzleMethod:@selector(originalMethod) withMethod:@selector(swizzledMethod) error:nil];
swizzledMethod上的以下代码进行递归!
[self originalMethod];
如何解决这个问题呢?
我使用以下库进行调配:
// JRSwizzle.h semver:1.0 // Copyright (c) 2007-2011 Jonathan 'Wolf' Rentzsch: http://rentzsch.com // Some rights reserved: http://opensource.org/licenses/MIT // https://github.com/rentzsch/jrswizzle #import <Foundation/Foundation.h> @interface NSObject (JRSwizzle) + (BOOL)jr_swizzleMethod:(SEL)origSel_ withMethod:(SEL)altSel_ error:(NSError**)error_; + (BOOL)jr_swizzleClassMethod:(SEL)origSel_ withClassMethod:(SEL)altSel_ error:(NSError**)error_; @end
解决方法
答案非常有趣:
[self swizzledMethod]; // will call originalMethod