iphone - Changing base url depending on preprocessor macro value -
i have project few schemes, 1 ea, staged, , production.
i want able set base url based on build configuration running.
#if defined production #define base_url [nsurl urlwithstring:@"https://example.production.com/"] #elif defined staged #define base_url [nsurl urlwithstring:@"http://example.staged.com/"] #else #define base_url [nsurl urlwithstring:@"https://example.ea.com/"] #endif
is there way set preprocessor macros in order define values of production , staged, i'm guessing it's somewhere in build settings of target. , best way it?
i store urls in nsobject class (aptly named urlhub) class methods so;
+(nsstring *)login { nsstring *url; if (developmentmode) { url = @"https://dev.mycoolwebservice/api/login"; } else { url = @"https://mycoolwebservice/api/login"; } return url; }
then wherever need use url can grab easily;
#import "urlhub.h" nsstring *url = [urlhub login];
this approach makes super simple update urls throught entire app since stored in same place.
in example switch on development urls need flip 1 bool , every url app-wide changes. ;)
Comments
Post a Comment