问题
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