0

I want to define a string variable which holds an IP Address globally,so that if in future the IPAddress got changed no need to go to each class file & update it, So for this what is the best way to implement whether to use plist or a global macro class or .pch file of my app?

0

3 Answers 3

2

Create a .h file. Say, GlobalMacros.h

In GlobalMacros.h

#define IP_ADDR @“SERVER_IP”

In your .pch file

import “GlobalMacros.h”

Now you can simply access the IP_ADDR anywhere.

0
1

Just create NSObject class and then place your URL in it and then access it and use it where you want.

in h file

#import <Foundation/Foundation.h>

@interface Config : NSObject {

}

//configuration section... 
extern  NSString        *SiteURL;
extern  NSString        *SiteAPIURL;

@end

in .m

#import "Config.h"

@implementation Config
//live
NSString        *SiteURL                = @"http://yourIP/";
NSString        *SiteAPIURL             = @"http://yourIP/";

@end 

in Prefix.pch just import it #import "Config.h"

and use it in the class where you want to use

NSString *apiURLString = [NSString stringWithFormat:@"%@login.php",SiteAPIURL];
1
  • This is a quite oo-style suggestion. If you get a bit further and apply a signleton pattern here, then it would be really nice. Aug 30, 2012 at 7:19
0

.pch file if you would never change it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.