5和更高版本中的poseAsClass

5和更高版本中的poseAsClass

本文介绍了替代在Mac OS X 10.5和更高版本中的poseAsClass?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Apple已弃用 NSObject 的 method for OS X v10.5以上。有没有其他方法让类构造工作?

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

推荐答案

我不认为有一个类级别的等价,可以交换两个方法的实现,这通常是使用 poseAsClass:的目的(当然,如果需要覆盖多个方法,可以交换多个方法类)。您希望在Objective-C 2.0运行时( #import objc / runtime.h )。警告:在调用method_exchangeImplementations之后,调用'new'方法实际上会调用原来的方法定义。

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.

这篇关于替代在Mac OS X 10.5和更高版本中的poseAsClass?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 06:36