Apple has deprecated NSObject
's poseAsClass:
method for OS X v10.5 and above. Is there another way to make class posing work?
views:
734answers:
3+1 and thank you for the excellent link
e.James
2009-08-17 21:23:44
+4
A:
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.
Barry Wark
2009-08-17 19:14:36
Thank you! I managed to get this to work, using a combination of mcandre's answer and the documentation that you linked to. A quick note: I had to `#include "objc/runtime.h"` in order to use the methods you describe.
e.James
2009-08-17 21:25:41
+2
A:
What are you trying to do? There are often ways around posing. I will concede, though, that it is sometimes the only way :)
Jonathan Dann
2009-08-18 08:46:15
I'm trying to keep track of all binding (and unbinding) messages in a Cocoa application. I want to `NSLog()` some debug information whenever a binding is made between one object and another. I ended up using `method_exchangeImplementations` on the binding methods for `NSObject`, and it did the trick.
e.James
2009-08-18 13:46:57
Sounds like you're Doing It Right :) I'd be wary of doing it in shipping code.
Jonathan Dann
2009-08-19 10:28:34