views:

72

answers:

2

Hi,

I need that I can use 1 object of NSString to use in all other files to access 1 variable in all filees

+4  A: 

Make this NSString a property of the AppDelegate class (or whatever your application delegate class is named). If the property is named myString, you can then access it via:

[[[UIApplication sharedApplication] delegate] myString];

To avoid warnings, you may want to import the AppDelegate class:

#import "AppDelegate.h"

...and expand the first code snippet into:

AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
[appDelegate myString];
Steve Harrison
That cast is unnecessary.
Chuck
@Chuck: Ah, thanks! I've corrected my answer accordingly.
Steve Harrison
+2  A: 

That's an unclear question.

If I understand correctly you want to have an global NSString* shared by multiple files. In that case, in one of the source files (.m), insert

NSString* my_global_string = @"...";

and in all other source files (or in a common .h), insert

extern NSString* my_global_string;
KennyTM