Alternative to poseAsClass in Mac OS X 10.5 and higher?

痴心易碎 提交于 2019-12-08 19:44:05

问题


Apple has deprecated NSObject's poseAsClass: method for OS X v10.5 and above. Is there another way to make class posing work?


回答1:


I don't think there is a class-level equivalent, but you can exchange the implementation of two methods, which was often the purpose of using poseAsClass: (of course, you can exchange more than one method if you need to override multiple methods in a class). You want method_exchangeImplementations in the Objective-C 2.0 runtime (#import objc/runtime.h). A word of warning: after calling method_exchangeImplementations, calling the 'new' method actually calls the original method definition.




回答2:


Lap Cat gives an alternative.




回答3:


What are you trying to do? There are often ways around posing. I will concede, though, that it is sometimes the only way :)



来源:https://stackoverflow.com/questions/1289757/alternative-to-poseasclass-in-mac-os-x-10-5-and-higher

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