开发者

how to declare a string global in iphone programing

开发者 https://www.devze.com 2023-04-12 18:57 出处:网络
I want to make a string global in the iphone application can any help me on this problem I have use extern and other things but these are not开发者_如何学运维 working on the xcode. They are giving the

I want to make a string global in the iphone application can any help me on this problem I have use extern and other things but these are not开发者_如何学运维 working on the xcode. They are giving the error.


This is the common way for Objective-C sources:

// .h
extern NSString* const MONString;

// .m
NSString* const MONString = @"MONString";


"expected specifier-qualifier-list before 'extern'"

That kind of error often results from an error on the previous line.


You, may use common class NSUserDefaults. There are methods:

NSUserefualts *def = [[NSUserDefaults standardUserDefaults];
[def setObject:*NSString* forKey:@"some key"];

and

*NSString* = [def ObjectForKey:@"some key"];

You can have access to standardUserDefaults in any place of your app. So Please, use it for storing and reading the global Strings or any other variables.


For that you have to directly write in to .pch file and that variable is access globally into project for that following example use to create the constant value for the entire project.

#define USERNAME @"Blah_blah" 

In that variable name is USERNAME and that value is Blah_blah. You can access the value of USERNAME access into entire project.

Happy codeing.....

0

精彩评论

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

关注公众号