Global Variables

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

  1. RPGamerL99 macrumors newbie

    Joined:
    Mar 10, 2008
    #1
    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

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    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

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #3
    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

    Joined:
    Jun 26, 2008
    #4
    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

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

    Joined:
    Mar 10, 2008
    #6
    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