Global Variables

Discussion in 'iOS Programming' started by RPGamerL99, Oct 5, 2008.

  1. RPGamerL99 macrumors newbie

    Mar 10, 2008
    Please tell me there is a way to make a variable open for any class in the program to use because i can not figure out how to get the drawView class to recognize variables i declared in App Delegate. it is because i am initiating some variables in applicationDidFinishLaunching. (OpenGL ES template under new project).
  2. robbieduncan Moderator emeritus


    Jul 24, 2002
    If you are doing this you are probably doing it wrong. Read up on proper OO design and the MVC pattern.
  3. firewood macrumors 604

    Jul 29, 2003
    Silicon Valley
    The OP asked about global variables, not about OO design and MVC patterns.

    You can use standard C conventions for declaring, instantiating and using global variables outside your Cocoa object declarations. Read any complete generic C tutorial. Be aware of the pitfalls of using global variables in large or reusable code projects.

  4. ayasin macrumors 6502

    Jun 26, 2008
    You can get at your delegate by using [[UIApplication sharedInstance] delegate] and casting it to your delegate, in the case you're describing you don't need global variables.
  5. RPGamerL99 thread starter macrumors newbie

    Mar 10, 2008
    I'm not sure how to use [[UIApplication sharedInstance] delegate] properly. Is there online documentation available?
  6. RPGamerL99 thread starter macrumors newbie

    Mar 10, 2008
    I decided to access those variables with methods, but for other classes to access those methods, they have to be in protocols right? Can someone show me how to implement a protocol or point me in the right direction?

Share This Page