On 2011 Feb 11, at 04:21, Joanna Carter wrote:

>  IMP anIMP = [anObject methodForSelector:@selector( myMethod: )];
>  [myDictionary setObject:anIMP forKey:myKey];

The compiler should warn you on that second line that an IMP is not an object.  
This code won't work.

> Or have I misunderstood what IMPs do?

You've misunderstood what an IMP *is*.

> In C#, a delegate knows about the "this", upon which the method will be 
> called, within itself and can simply be called without having to go through 
> any gymnastics to get the target object. Isn't this what IMPs do?

The equivalent of C++ 'this' in Objective-C is 'self'.  But as you said, 'this' 
is an object, not a method.

If you want to store a method, you could probably wrap that the pointer value 
of an IMP as an NSValue.  Read NSValue.  Or, for persistent storage, store the 
method name you get from NSStringFromSelector(), then retrieve it with 
NSSelectorFromString().  Use the latter technique sparingly because the 
compiler cannot warn you about undefined methods, etc. - think JavaScript.

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to