Re: Switching methods in private classes in Apple frameworks

2010-03-12 Thread Scott Morrison
You can access ivars just #include "objc/objc-class.h" and then use static Ivar theIvar; //create a static to cache the ivar information if (!theIvar) theIvar = class_getInstanceVariable([self class], "ivarName"); //look up the ivar information and cache it id aValue =

Re: Switching methods in private classes in Apple frameworks

2010-03-12 Thread Paul Sanders
ually worry me all that much. Paul Sanders. - Original Message - From: "Bill Bumgarner" To: "Gideon King" Cc: "Cocoa Dev" Sent: Friday, March 12, 2010 6:36 AM Subject: Re: Switching methods in private classes in Apple frameworks Where "careful about

Re: Switching methods in private classes in Apple frameworks

2010-03-12 Thread Daniel DeCovnick
Wow, that's really, really awesome. Do you have any more details on why you can't use ivars? Not calling super makes sense. Can you access properties? On Mar 11, 2010, at 8:58 PM, Gideon King wrote: Thanks Jerry, I should mention that I did get this caveat note from Greg Parker (Apple's "ru

Re: Switching methods in private classes in Apple frameworks

2010-03-12 Thread Jean-Daniel Dupas
Method exchange is dangerous because if the target class (NSConcreteNotification) does not override the target function (dealloc), you may exchange it's superclass dealloc method instead and may end up overriding a method in a base class. Use it with great care and avoid it in production code i

Re: Switching methods in private classes in Apple frameworks

2010-03-11 Thread Bill Bumgarner
On Mar 11, 2010, at 8:58 PM, Gideon King wrote: > So as long as you are careful about what you do, yes it is entirely possible > to replace methods at will. I hope nobody misuses it, but it certainly was > essential in my debugging - yes, I found it! Yay! Where "careful about what you do" inc

Re: Switching methods in private classes in Apple frameworks

2010-03-11 Thread Gideon King
Thanks Jerry, I should mention that I did get this caveat note from Greg Parker (Apple's "runtime wrangler"): "..you must be cautious about what your replacement method does. In particular, you must not use any of the class's ivars and you must not call [super something]. As long as you follow

Re: Switching methods in private classes in Apple frameworks

2010-03-11 Thread Jerry Krinock
On 2010 Mar 11, at 18:00, Gideon King wrote: > This is really cool...so I can replace a method without being a subclass or > category. I just need to chime in here, in case anyone missed it, to emphasize how *ALL-CAPS COOL* this is indeed. In the ReadMe of Apple's MethodReplacement.zip sample

Re: Switching methods in private classes in Apple frameworks

2010-03-11 Thread Gideon King
This is really cool...so I can replace a method without being a subclass or category. So I implemented an NSObject subclass with the new method, and did the method exchange, and my new method was called instead of the old one, but I had a problem - the call to the switched out method (dealloc

Re: Switching methods in private classes in Apple frameworks

2010-03-11 Thread Greg Parker
On Mar 11, 2010, at 4:24 PM, Gideon King wrote: > (following on from the thread "How to debug this error on closing a > document?", but it's really moved on to a new topic at this point) > > I was not aware that poseAsClass is not available in 64 bit applications. I > looked at the Apple example

Switching methods in private classes in Apple frameworks

2010-03-11 Thread Gideon King
(following on from the thread "How to debug this error on closing a document?", but it's really moved on to a new topic at this point) I was not aware that poseAsClass is not available in 64 bit applications. I looked at the Apple example of exchanging a method in NSWindow, and it looked easy e