开发者

How can we have a single resource file which contains URLs or constant members and we use them all over the application?

开发者 https://www.devze.com 2023-03-03 06:37 出处:网络
In iPhone , I just want to store all URL at global level so that I should be able to access those by开发者_开发问答 some id or something . I found out one way like implementing a category for NSObject

In iPhone , I just want to store all URL at global level so that I should be able to access those by开发者_开发问答 some id or something . I found out one way like implementing a category for NSObject so that we can access those members everywhere as all the classes are subclassed from NSObject . But I don't like this way . Is there a simple and smarter way to do this. This is gonna save a lot of time each time I want to change the value of any of the URL .

Thank you all in advance !!


You can include all your url into a separate header file (*.h) that you can import into all classes which needs them. There you can write a static constant or a preprocessor #define statement

static NSString * const kSampleURL = @"http://stackoverflow.com";

or

#define kSampleURL @"http://stackoverflow.com"


Its better you code-in all your constant attributes in some file named "Constants.h". Strings can be written down as:

static const NSString *kURL = @"www.google.com";

And include this Constants.h file in the pch file so that your constants are available throughout the project.

0

精彩评论

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