• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: address of method in a class instance
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: address of method in a class instance


  • Subject: Re: address of method in a class instance
  • From: Peter Ammon <email@hidden>
  • Date: Wed, 5 Sep 2001 16:59:51 -0400

On Wednesday, September 5, 2001, at 01:52 PM, Robert S Goldsmith wrote:

Hi :)

This one really has me stuck.

As we have been discussing, CoreFoundation is a bit different from Foundation. As I have the pleasure of using it I am now in the situation where, to get callbacks to work correctly when wrapped in an ObjC class, I need a pointer to a function.

The CF callbacks are based on C and as such ask you to pass a pointer to a function that gets run when the event occurs. This is fine if you only have one instance of a class (you can hack it with bits of C) but I am not happy with that.

What I need is a way to get hold of the address of an ObjC class instance member method. This way I can pass the address and when the callback happens, the correct instance is notified ...

You can get ahold of a pointer to a method (called an IMP) using methodForSelector:. Here's an example for a method that takes a double and an object, and returns an int.

typedef double(* myFuncType)(id, SEL, double, id);

myFuncType myFunc=(myFuncType)[anObject methodForSelector:someSelector];

Note, that, however, this function can't serve as a callback because it takes the initial id and SEL parameters. I suggest using a standard C function and passing a pointer to your object in the info parameter.

[...]

-Peter


References: 
 >address of method in a class instance (From: Robert S Goldsmith <email@hidden>)

  • Prev by Date: Re: Dirent?
  • Next by Date: Re: self and _cmd
  • Previous by thread: Re: address of method in a class instance
  • Next by thread: Re: address of method in a class instance
  • Index(es):
    • Date
    • Thread