Re: Performing the selector from a stored IMP
Re: Performing the selector from a stored IMP
- Subject: Re: Performing the selector from a stored IMP
- From: Jean-Daniel Dupas <email@hidden>
- Date: Fri, 11 Feb 2011 14:51:03 +0100
Le 11 févr. 2011 à 14:31, Joanna Carter a écrit :
> Hi Jerry
>
>> You've misunderstood what an IMP *is*.
>
> Heheheh, I thought as much :-)
>
>> 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.
>
> (Fortunately, I don't know anything much about JavaScript, so hopefully that's less confusing)
>
> Anyway, from what you are saying, it would appear that NSSelectorFromString() would still need the target object in order to perform the selector, so that is just as useless :-)
>
> Whilst waiting for replies I have been busy rationalising things out and have come to the solution of declaring a MyDelegates protocol with the three delegate methods on it, implementing the protocol on the class, upon which I want to call the methods, and storing id<MyDelegates> references in the dictionary.
>
> This ensures that only a valid object, which implements the three delegates can be added to my static dictionary wrapper class and that that the wrapper class returns a valid (typesafe) instance with the three delegates available.
>
> I really am going to have to do some more reading to find out if and when I might want to use an IMP.
The short answer is never. IMP is a low level detail of the runtime and is useful only in very few specific cases.
Have a look at the following article for a better understanding of the runtime, and what IMP are for:
http://www.mikeash.com/pyblog/friday-qa-2009-03-20-objective-c-messaging.html
-- Jean-Daniel
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden