• 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: NEWBIE: Multiple class communication without DO
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NEWBIE: Multiple class communication without DO


  • Subject: Re: NEWBIE: Multiple class communication without DO
  • From: Charilaos Skiadas <email@hidden>
  • Date: Fri, 5 Aug 2005 15:27:21 -0500

I was waiting for someone with more experience to answer this, but given that there where no takers, I'll give you some ideas. The thing is that there are lots of ways to do it, and they all depend on your program structure.

First of all, it might make sense to make PrefController a "shared Instance", i.e. a singleton. (ok, actually those two don't mean the same thing necessarily.)
I am guessing this is for the application preferences? Then that's how I would go about it.


Anyway, this is not really related to how to exchange the information. Well, for that, when your controller creates prefsController, it probably does so through some init method. So you could create a custom subclass for prefsController, with its own initWithCurrentItems:andController: method, which method further passes to the the prefsController both the items necessary, and a reference to the controller. then it can store this information in some local variables and use them when needed.
The problem with that is that you need to make sure you don't end up in a retain cycle. I.e. your controller has retained the prefsController, so your prefsController should not retain controller, because then they wouldn't be able to ever get dealloced, not until the app closes.
So the danger with that is that you have to make sure controller does not get dealloced and prefsController sends it information after that happens. This is the part that heavily depends on your app's implementation.


Another approach is for controller to set itself as the prefsController's delegate, when it creates it, and then make sure to unset itself before it gets dealloced. Then prefsController can simply send messages to its delegate. This is basically the same approach as before, except that some of the worrying is taken care of for you by the setDelegate method.

A question you should ask yourself is, do controller and prefsController need to know about each other? If they don't you could also use notifications, possibly, again depending on the structure of your app.

Anyway, just some food for thought. I hope it is a bit helpful, and that some more experienced programmers will chime in and correct my mistakes and offer other better suggestions.
But if you can provide us some more information about your project, and the roles Controller and prefsController are playing in it, maybe we could help more.
On Aug 5, 2005, at 2:29 AM, Benjamin D. Jones wrote:

I've finally hit that point in my knowledge of cocoa that the app I'm working needs to have more than one primary class controlling it. I'm adding preference windows and other windows that I'd like to have on a seperate controller. My problem is that even if I follow the examples I've been given I don't think i truely understand how to correctly code the communication. Any suggestions?


P.S. This is how I've been trying to set it up... but I need to get a NSArray from one class to the other during run time.

Class name - Controller & PrefsController
Controller launches PrefsController's window and sends it a current item list
PrefsController stores it in NSUserDefaults and loads the last 10 list items from the last session, along with the various values for the actual preferences window. And sends the old list back to Controller.


Hope thats clear enough... as you can tell i'm confusing myself a lot :)

Benjamin D. Jones
email@hidden

Haris


_______________________________________________ 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: 
 >NEWBIE: Multiple class communication without DO (From: "Benjamin D. Jones" <email@hidden>)

  • Prev by Date: Crackpot Idea for Core Data Multi-User Document
  • Next by Date: Re: IntelliJ IDEA 5.0
  • Previous by thread: NEWBIE: Multiple class communication without DO
  • Next by thread: Re: NEWBIE: Multiple class communication without DO
  • Index(es):
    • Date
    • Thread