• 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: Possible to determine who called a method?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Possible to determine who called a method?


  • Subject: Re: Possible to determine who called a method?
  • From: Mike Abdullah <email@hidden>
  • Date: Thu, 1 Nov 2007 18:38:59 +0000

No, this is not properly possible. It rather breaks encapsulation if it did work. I would go with adding a "caller" or similar argument to the method. Rather like IB does:

- (IBAction)doSomething:(id)sender;

On 1 Nov 2007, at 18:19, Ken Tozier wrote:

Hi

Say you have several objects "A," "B," "C," which contain references to each other in an NSArray. Is it possible inside each object's doSomethingAmazing method to determine which object called it? For example: Say Object C receives a doSomethingAmazing invocation. It should do its thing and then notify it's siblings to run their own doSomethingAmazing methods but because each contains references to all the others, it could enter an infinite loop. Here's an example:

- (void) doSomethingAmazing
{
/* do amazing stuff here */

// now tell objects in refList to run their own doSomethingAmazing methods
NSEnumerator *enumerator = [refList objectEnumerator];
id ref;

while (ref = [enumerator nextObject])
{
if (ref != callingObject)
[ref doSomethingAmazing];
}
}


I know I could do this by adding another argument (say "caller") to the doSomethingAmazing method but would like to avoid that if possible.

Anyone know if caller detection is possible?

Thanks for any help

Ken
_______________________________________________

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

_______________________________________________

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


References: 
 >Possible to determine who called a method? (From: Ken Tozier <email@hidden>)

  • Prev by Date: Re: NSBitmapImageRep byte/color component ordering
  • Next by Date: No results with my custom documents during spotlight search
  • Previous by thread: Possible to determine who called a method?
  • Next by thread: Re: Possible to determine who called a method?
  • Index(es):
    • Date
    • Thread