• 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: Iain Delaney <email@hidden>
  • Date: Tue, 24 May 2005 12:50:32 -0400

Thanks to all who replied, I've got it working now.
The object that instantiated them might not be around for long, so it would be a bit dangerous for the objects to know about it. You could pass a pointer to the appController, if that's really what you need, but unless you retain the controller, there is no guarantee it is going to be around, and you should absolutely NOT retain the controller, because you'll probably get a retain cycle, that is if the controller has retained the object. But there might be other ways of accomplishing what you want to do, maybe more obj- C-friendly. So the question is, what are you trying to accomplish?

Charilaos: The object in question is my AppController, so I can guarantee it will be around for the life of the program. In fact, I think it was the retain cycle that gave me a problem in the first place, so removing that helped a lot. Thanks.
----------------------------------------------------------

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.

Ondra: I ended up going with the first solution, although this one seems more elegant. The one thing I don't understand how the worker 'knows' what MyController is.
------------------------------------------------------

You could pass it as a parameter to the object's -init... method(s).
You could add a set... method to the class and call it from the AppController.
If the object is instantiated in a nib, you could make the member
variable an outlet, and connect it in IB.


Clark: Thanks, that's pretty well what I ended up doing. These objects are all in my Model/Controller layer, so IB isn't much help.
_______________________________________________
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
  • Prev by Date: Re: Save table sort order to User Defaults
  • Next by Date: NSTextStorage subclassing issue in 10.4
  • Previous by thread: Re: Object References in Obj-C
  • Next by thread: [SOLVED] NSTableView vs. NSUserDefaultsController
  • Index(es):
    • Date
    • Thread