PDA

View Full Version : Using objects created in other classes




DonCamillo
Jul 21, 2009, 03:09 AM
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?



whooleytoo
Jul 21, 2009, 12:08 PM
You could:
- create two IBOutlets in your ViewController class pointing to the two stream objects
or
- create one IBOutlet pointing to the AppDelegate itself and you can call methods in the AppDelgate or access the streams
or
- 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.