• 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: Object References in Obj-C
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Object References in Obj-C


  • Subject: Re: Object References in Obj-C
  • From: Ondra Cada <email@hidden>
  • Date: Mon, 23 May 2005 17:05:04 +0200

Iain,

On 23.5.2005, at 16:49, Iain Delaney wrote:

Here's my situation: My AppController has a dictionary of objects. One of these objects creates a worker object that may need to get information from another object in the dictionary. Do Obj-C objects know anything about the object that instantiated them?

Nope.

Or should I pass a pointer to the parent or AppController around?

That's the solution.

Right now, I've got a member variable of type (AppController *) MyApp

(incidentally, variable names should begin by a lowercase)

that I set with self from inside the AppController class, but I'm not that comfortable with that. Is this the right way to do things, or is there a better way?

Depends. In this very case it might be best just to tell the created object (something like, instead of [[MyWorker alloc] init] there would be [[MyWorker alloc] initWithOwner:self]) -- that is, I believe, more or less your solution, the initWithOwner would just fill the "myApp" variable of yours.


Or presumed your controller is a singleton, you can implement an extra accessor owner-level, like

@implementation MyController
static MyController myself=null;
-init { // or awakeFromNib, or whatever method you use for initialization
...
return myself=self;
}
+(MyController*)sharedController { return myself; }
...


and the worker would use [MyController sharedController] to access the thing.

Or you can use notifications.
---
Ondra Čada
OCSoftware:     email@hidden               http://www.ocs.cz
private         email@hidden             http://www.ocs.cz/oc


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Object References in Obj-C (From: Iain Delaney <email@hidden>)

  • Prev by Date: Re: Object References in Obj-C
  • Next by Date: Re: Object References in Obj-C
  • Previous by thread: Re: Object References in Obj-C
  • Next by thread: Re: Object References in Obj-C
  • Index(es):
    • Date
    • Thread