Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

trey5498

macrumors regular
Original poster
Jun 16, 2008
191
0
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.
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
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.

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
 

trey5498

macrumors regular
Original poster
Jun 16, 2008
191
0
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.
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.