ParisNakitaKejser
ParisNakitaKejser

Reputation: 14839

How can i create a global NSString?

Hei all

i try to learn how i can get a NSString global, i have this kind of files.

( my global class )

Globals.h 
Globals.m

( my first view )

FirstViewController.h
FirstViewController.m

( my secound view )

SecoundViewController.h
SecoundViewController.m

now i will make a kind of username in FirstViewController and when SecoundViewController loads its will make my input into NSLog() in first time.

hobe i can be help here, :)

Upvotes: 1

Views: 932

Answers (1)

thomashw
thomashw

Reputation: 956

If you truly want a global string, you can simply define it outside of any class definition, function, etc. in your Global class.

In Global.h:

extern NSString *globalString;

In Global.m:

NSString *globalString = @"a string";

To reference it in another class:

#import Global.h
...
NSString *aString = globalString;
...

If you simply want to pass a string from your first view to your second, look into properties.

Upvotes: 3

Related Questions