Using objects created in other classes

Discussion in 'Mac Programming' started by DonCamillo, Jul 21, 2009.

  1. DonCamillo macrumors newbie

    Jul 21, 2009
    hi there

    I'm new in programming Objectiv-C and Cocoa. To learn it I decided to do a little project where I have some questions now.
    I created a connection to a server with NSStream object which results in two objects: an outputStream object and an inputStream object. These two objects are created in my AppDelegate.m file in applicationDidFinishLaunching method at the startup of my application. In this file I can use the objects as I want. But to use a UI I also had to create a ViewController file where I want to use these objects now. How can I create a link between these two files?
  2. whooleytoo macrumors 604


    Aug 2, 2002
    Cork, Ireland.
    You could:
    - create two IBOutlets in your ViewController class pointing to the two stream objects
    - create one IBOutlet pointing to the AppDelegate itself and you can call methods in the AppDelgate or access the streams
    - create an IBOutlet in the AppDelegate pointing to the ViewController, and put the code there.

    (if you're not familiar with IBOutlets, you declare them in your header file, then connect them visually in Interface Builder).

    Any of those would work, it's just important to try and keep the networking code together and 'modular' as much as possible, so you don't have some in the AppDelegate, some in the ViewController, etc.

Share This Page