Header files

Discussion in 'Mac Programming' started by trey5498, Jul 16, 2008.

  1. trey5498 macrumors regular

    Joined:
    Jun 16, 2008
    #1
    This will be my last stupid question as I am done with the project and I was wondering. It has been quite some time since I have crossed over header files.

    For example, if I have appControl.m and appControl.h and the header files has 30 variables I plan on using in, lets say 3 other .m files, would i make those variables global?

    IE:
    Code:
    +(NSString *)test;
    or how would I go about that? a simple #import "appControl.h" doesnt work.

    Thank you in advance.
     
  2. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    Are the three other .m files different classes? If not, they probably should be. If so, they need some other means of accessing the data in your appControl class. Global variables are very, very rarely the correct answer to any question. extern is the way to indicate in one source file that there is a variable with that name that is defined elsewhere, but I think you should explain what these variables are and why they need to be accessed in so many places without the use of accessors in an object, etc.

    -Lee
     
  3. trey5498 thread starter macrumors regular

    Joined:
    Jun 16, 2008
    #3
    well in the last project I had 17 different buttons that were declared in the appControl.h and I tried to pass them to other class files. Was thinking there had to be a better way than just have all the button control code in one class file. It was quite the big file.
     
  4. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #4
    I'm not an expert, but my understanding is that the implementation for an Objective-C class needs to be in the same file. XCode supports #pragma marks, which make it very easy to navigate through a source file without a lot of scrolling.

    One option might be to make helper functions that are not class members, and call those from your existing functions, passing in the necessary variables. I think this would be more confusing than just having everything in the same file, and I would only consider this if more than one class were to use these helper functions.

    -Lee
     

Share This Page