Reputation: 183
I need that I can use 1 object of NSString to use in all other files to access 1 variable in all filees
Upvotes: 0
Views: 193
Reputation: 523184
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;
Upvotes: 3
Reputation: 125470
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];
Upvotes: 4