如何从混乱中调用原始方法? [英] How to call the original method from swizzled one?

查看:79
本文介绍了如何从混乱中调用原始方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从混乱的状态中调用原始方法?

How to call the original method from swizzled one?

原始方法已替换为代码:

The original method is replaced by the code:

[[UIWindow class] jr_swizzleMethod:@selector(originalMethod) withMethod:@selector(swizzledMethod) error:nil];

swizzledMethod上的以下代码进行递归!

The following code on swizzledMethod makes recursion!

[self originalMethod];

如何解决这个问题?

我使用以下库进行缓存:

I use the following library for swizzling:

// 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

这篇关于如何从混乱中调用原始方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆