文档章节

one-stop-shop for all your method swizzling needs

m
 mingxun
发布于 2014/04/27 16:10
字数 474
阅读 58
收藏 0

JRSwizzle

Description

JRSwizzle is source code package that offers a single, easy, correct+consistent interface for exchanging Objective-C method implementations ("method swizzling") across many versions of Mac OS X, iOS, Objective-C and runtime architectures.

More succinctly: JRSwizzle wants to be your one-stop-shop for all your method swizzling needs.

Download

$ cd /path/to/top/of/your/project
$ git submodule add git://github.com/rentzsch/jrswizzle.git JRSwizzle semver-1.x
$ git submodule init && git submodule update

# OPTIONAL: Execute the following commands if you want to explicitly peg
# to a certain version. Otherwise `git submodule update` will keep you
# current with HEAD.

$ cd JRSwizzle
$ git checkout v1.0

Reasons for Existence

  • Easy: Just do this: [SomeClass jr_swizzle:@selector(foo) withMethod:@selector(my_foo) error:&error];Voila.

  • Correct: There's a subtle interaction between method swizzling and method inheritance. Following in Kevin Ballard's footsteps, this package Does The Right Thing.

  • Compatible: JRSwizzle should Just Work on any version of Mac OS X and iOS you care about. Here's the exhaustive compatibility list:

    • Mac OS X v10.3/ppc (Ballard implementation)

    • Mac OS X v10.4/ppc (Ballard implementation)

    • Mac OS X v10.4/i386 (Ballard implementation)

    • Mac OS X v10.5/ppc (method_exchangeImplementations+Ballard implementation)

    • Mac OS X v10.5/i386 (method_exchangeImplementations+Ballard implementation)

    • Mac OS X v10.5/ppc64 (method_exchangeImplementations+Ballard implementation)

    • Mac OS X v10.5/x86_64 (method_exchangeImplementations+Ballard implementation)

    • iOS 2.0+ (method_exchangeImplementations+Ballard implementation)

  • Robust: All parameters are checked and JRSwizzle returns an optional NSError with high-quality diagnostics.

Support

Please use JRSwizzle's GitHub Issues tab to file bugs or feature requests.

To contribute, please fork this project, make+commit your changes and then send me a pull request.

Comparison

There's at least four swizzling implementations floating around. Here's a comparison chart to help you make sense of how they relate to each other and why JRSwizzle exists.

Scenario Swizzle Technology Method Implementation Correct Behavior 10.4 64-bit
1 Classic Direct YES YES NO
2 Classic Inherited NO YES NO
3 Ballard Direct YES YES NO
4 Ballard Inherited YES YES NO
5 Apple Direct YES NO YES
6 Apple Inherited NO NO YES
7 JRSwizzle Direct YES YES YES
8 JRSwizzle Inherited YES YES YES

License

The source code is distributed under the nonviral MIT License. It's the simplest most permissive license available.

Version History

  • v1.0: Mar 2 2012

  • v1.0d1: May 31 2009

    • [FIX] Soothe valgrind by nulling out hoisted_method_list->obsolete, which it apparently reads. (Daniel Jalkut)

    • [FIX] Xcode 3.2 apparently now needs ARCHS set explicitly for 10.3 targets. (rentzsch)

  • v1.0d0: Apr 09 2009

    • Moved to github.

  • v1.0d0: Dec 28 2007

    • Under development.


本文转载自:https://github.com/rentzsch/jrswizzle

m
粉丝 5
博文 138
码字总数 9074
作品 0
崇明
私信 提问
Objective-C Runtime(四)isa swizzling

Runtime 4 isa swizzling Objective-C Runtime(一) 简介 对象、类的结构 消息传递(Messaging) Objective-C Runtime(二) 动态方法解析和转发 Objective-C Runtime(三) Method Swizzli...

liuyanhongwl
2018/03/27
0
0
Method Swizzling

本文由TracyYih[博客]翻译自NSHipster的文章Method Swizzling。 在上周associated objects一文中,我们开始探索Objective-C运行时的一些黑魔法。本周我们继续前行,来讨论可能是最受争议的运...

mingxun
2014/02/25
68
0
Objective-C Method Swizzling

Method Swizzling已经被聊烂了,都知道这是Objective-C的黑魔法,可以交换两个方法的实现。今天我也来聊一下Method Swizzling。 使用方法 我们先贴上这一大把代码吧 好的,上面就是Method Sw...

Sunxb
05/16
0
0
关于Swift4.0 Method Swizzling(iOS的hook机制)使用

关于Method Swizzling 原理什么的有很多帖子讲述的已经很清楚这里不再赘述, 这里仅仅处理Method Swizzling 在swift4.0中的使用方法 因为Swift本身对Runtime的支持并不是很到位,尤其是Metho...

冰泪_
2018/09/26
635
0
ios method swizzling

背景 最近在整理项目逻辑的时候,发现一个问题:就是打点统计,经常和代码业务逻辑混在了一起,耦合性很强,并且经常容易出错。于是就在思考怎样对这一块进行优化。 其实,对这方面的讨论一直...

zachwang
2017/11/29
0
0

没有更多内容

加载失败,请刷新页面

加载更多

db.properties

jdbc.driver=com.mysql.cj.jdbc.Driverjdbc.url=jdbc:mysql://localhost:3306/mybatis?serverTimezone=GMT%2B8&characterEncoding=utf8&useSSL=falsejdbc.username=rootjdbc.pas......

行者终成事
18分钟前
3
0
从 Storm 到 Flink,汽车之家基于 Flink 的实时 SQL 平台设计思路与实践

在 2019 年之前,之家的大部分实时业务都是运行在 Storm 之上的。Storm 作为早期主流的实时计算引擎,凭借简单的 Spout 和 Bolt 编程模型以及集群本身的稳定性,俘获了大批用户。下图是实时计...

阿里云官方博客
18分钟前
4
0
网络安全-Day04

2.1.1 什么是SQL注入 2.1.2 注入分类 2.1.3 MySQL手工注入 2.1.4 sqlmap使用 2.1.5 总结 什么是SQL注入 SQL注入漏洞原理 什么是SQL 结构化查询语言(Structured Query Language),是一种特殊目...

Jerry1101
19分钟前
3
0
docker容器内安装yum,vim等命令,以及配置ls指令

使用国内镜像 mv /etc/apt/sources.list /etc/apt/sources.list.bakecho "deb http://mirrors.163.com/debian/ jessie main non-free contrib" >> /etc/apt/sources.listecho "deb http://......

长恭
19分钟前
3
0
超详细的MySQL8.0.17版本安装教程

下载MySQL MySQL的官网地址:https://www.mysql.com/。 如下图所示: 然后点击DOWNLOADS ==> Community,选择MySQL Community Server。如图所示: 滑到页面的最下面,找到Recommended Downl...

彩色泡泡糖
22分钟前
3
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部