How do I call the original function from the overloaded function in a category?

僤鯓⒐⒋嵵緔 提交于 2019-12-05 12:45:29
Ferruccio

From the Mac OS X Reference Library:

When a category overrides an inherited method, the method in the category can, as usual, invoke the inherited implementation via a message to super. However, if a category overrides a method that already existed in the category's class, there is no way to invoke the original implementation.

How do you guys feel about this?

Grab the original method address for initWithCoder at runtime and store it in a static variable. Do a method swizzle on it to replace the classes implementation with the my initWithCoder. And then in my initWithCoder, I would call the original method stored in the static variable.

You can put it in a category and call this class initialization step at the start of the program, making sure it can't be called twice, or if it is it does nothing.

It seems dangerous, but I feel like it should work.

Surya

Method swizzling should work as kidnamedlox suggested .

Your exact same question was discussed in this Stanford itunes class by Evan Doll

https://podcasts.apple.com/us/podcast/iphone-application-programming-spring-2009/id384233222

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!