2

Since class_poseAs(..) is deprecated in Objective-C 2.0, I need to find another way to change the class of an object at runtime. I've found I can change an object's class using object_setClass(..). My problem now is finding all the current instances of a given class in order to update them.

A solution would be to maintain a global dictionary of the instances I want to potentially update, but I'd like to know whether there's already a way to obtain such a collection from the reflective api.

I checked Apple's Runtime reference and I cannot find anything useful. Updating just the method of a class with method_exchangeImplementations(..) is not a solution for me since I want to be able to reuse the old implementation by using super.

4

1 回答 1

2

通常,如果您想用自己的方式交换特定类中各种方法的实现,您可以使用 Objective-C 2.0 运行时中的method_exchangeImplementations()函数。(你需要#import objc/runtime.h)。这比尝试换出实际类要简单得多,因为poseAsClass:在 64 位运行时已弃用且不可用。

于 2010-02-19T00:09:56.103 回答