forum

Home / DeveloperSection / Forums / Issue with global variables in Objective-C

Issue with global variables in Objective-C

zack mathews 1393 15-Dec-2015

Learn this paragraph that is taken from the Cocoa programming documentation:

You will be registering, reading, and setting defaults in several classes in your application. To make sure that you always use the same name, you should declare those strings in a single file and then simply #import that file into any file in which you use the names. There are several ways to do this. For example, you could use the C preprocessor’s #define command, but most Cocoa programmers use global variables for this purpose.

Is this really the correct best practice? Global variables? That seems insane to me – counter to everything I’ve ever been taught.

Would a better design be a simple Singleton class with these defined? Or is it really the correct best practice to go global? Is there a better pattern than either, given that many people consider Singletons to be globals in a pretty dress?


Updated on 15-Dec-2015

Can you answer this question?


Answer

1 Answers

Liked By