• 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: Robert S Goldsmith <email@hidden>
  • Date: Thu, 06 Sep 2001 11:03:56 +0100

Hi :)


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

Yeah, an excellent one: get rid of CF and use Foundation.

I wish I could, but the IOKit usb stuff uses CF callbacks and there is nothing I can do about that.

The solution, it seems, based on everyones great help was:

1)Have a c function as the callback
2)pass self in the refCon field of the callback setup
3)use this refCon field to message the correct instance of the class with the iterator the callback returns
4)In the class instance, do what is needed on that event (eg. someone unplugging the usb device) and send a notification.
5)In the main class instance, listen for this notification and do things like changing the icon showing whether the usb device is plugged in or not.

As was suggested, CF callbacks work fine combined with NSApplication runloops (because they are based on the same thing in reality).

:)

Can anyone see a problem with all this? It seems to work...

For instance, is there any way the instance of the class responding to the callbacks could be destroyed without me knowing about it? This could cause a problem with the callback trying to message an instance that no longer exists. Is there an equivilent to 'init' that is called before 'dealloc' so I could catch that posibility?

Robert


  • Follow-Ups:
    • Re: address of method in a class instance
      • From: Andreas Monitzer <email@hidden>
References: 
 >address of method in a class instance (From: Robert S Goldsmith <email@hidden>)

  • Prev by Date: NSColorWell setColor crash FIXED ?
  • Next by Date: Re: [Newbie] Uninitialized outlets?
  • 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