开发者

How can i create a global NSString?

开发者 https://www.devze.com 2023-03-14 20:41 出处:网络
Hei all i try to learn how i can get a NSString global, i have this kind of files. ( my global class ) Globals.h

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 )

SecoundViewCo开发者_高级运维ntroller.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, :)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号