Objective c 如何从Swizzle方法调用原始方法?

Objective c 如何从Swizzle方法调用原始方法?,objective-c,Objective C,如何从Swizzle方法调用原始方法 原始方法由以下代码替换: [[UIWindow class] jr_swizzleMethod:@selector(originalMethod) withMethod:@selector(swizzledMethod) error:nil]; swizzledMethod上的以下代码进行递归 [self originalMethod]; 如何解决这个问题 我使用以下库进行滑动: // JRSwizzle.h semver:1.0 // Copyri

如何从Swizzle方法调用原始方法

原始方法由以下代码替换:

[[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
//JRSwizzle.h semver:1.0
//版权所有(c)2007-2011 Jonathan‘Wolf’Rentzsch:http://rentzsch.com
//保留部分权利:http://opensource.org/licenses/MIT
//   https://github.com/rentzsch/jrswizzle
#进口
@接口对象(JRSwizzle)
+(BOOL)jr_swizzle方法:(SEL)origSel_uuu方法:(SEL)altSel_u错误:(NSError**)错误;
+(BOOL)jr_swizzleClassMethod:(SEL)origSel_uuwith classmethod:(SEL)altSel_uuerror:(NSError**)error_u;
@结束

答案非常有趣:

[self swizzledMethod]; // will call originalMethod

调用您自己的方法。。。你刷了指针,但没有刷名字。 e、 g

原始资金=123美元 myFunc=$321

swizzle=>

原始资金=321美元 myFunc=$123


因此,为了调用最初的$123,我们现在调用myFunc

我已经为iOS5创建了方法swizzling

我在这里做了一个解释

基本上,对原始方法的每个调用都将属于您。因此,对方法的每次调用都应该指向原始方法。(如果swizzle设置正确)


希望这有帮助

链接问题:@Altaveron是对的,我只是再次解释了一遍,因为我第一次也爱上了它。。。几次:D