Last active
December 22, 2015 08:29
-
-
Save westonplatter/6445784 to your computer and use it in GitHub Desktop.
How to reference environment specific iOS Enviroment Variables. Followed this example, and updated to reflect ARC usuage.
http://blog.carbonfive.com/2011/06/20/managing-ios-configurations-per-environment-in-xcode-4/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="UTF-8"?> | |
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
| <plist version="1.0"> | |
| <dict> | |
| <key>Release</key> | |
| <dict/> | |
| <key>Debug</key> | |
| <dict> | |
| <key>apiUrl</key> | |
| <string>http://localhost:3000/api/v1/</string> | |
| </dict> | |
| </dict> | |
| </plist> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // Environment.h | |
| // Visible | |
| // | |
| // Created by weston on 9/4/13. | |
| // Copyright (c) 2013 Visible. All rights reserved. | |
| // | |
| #import <Foundation/Foundation.h> | |
| @interface Environment : NSObject | |
| @property (nonatomic, strong) NSString *apiUrl; | |
| + (Environment *)sharedInstance; | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // Environment.m | |
| // Visible | |
| // | |
| // Created by weston on 9/4/13. | |
| // Copyright (c) 2013 Visible. All rights reserved. | |
| // | |
| #import "Environment.h" | |
| @implementation Environment | |
| static Environment *sharedInstance = nil; | |
| - (id)init | |
| { | |
| self = [super init]; | |
| return self; | |
| } | |
| - (void)initializeSharedInstance | |
| { | |
| NSString* configuration = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"Configuration"]; | |
| NSBundle* bundle = [NSBundle mainBundle]; | |
| NSString* envsPListPath = [bundle pathForResource:@"env" ofType:@"plist"]; | |
| NSDictionary* environments = [[NSDictionary alloc] initWithContentsOfFile:envsPListPath]; | |
| NSDictionary* environment = [environments objectForKey:configuration]; | |
| _apiUrl = [environment valueForKey:@"apiUrl"]; | |
| } | |
| #pragma mark - Lifecycle Methods | |
| + (Environment *)sharedInstance | |
| { | |
| @synchronized(self) { | |
| if (sharedInstance == nil) { | |
| sharedInstance = [[self alloc] init]; | |
| [sharedInstance initializeSharedInstance]; | |
| } | |
| return sharedInstance; | |
| } | |
| } | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // LoginViewController.m | |
| // Visible | |
| // | |
| // Created by weston on 9/4/13. | |
| // Copyright (c) 2013 Visible. All rights reserved. | |
| // | |
| #import "LoginViewController.h" | |
| #import "Environment.h" | |
| @implementation LoginViewController | |
| - (void)viewDidLoad { | |
| [super viewDidLoad]; | |
| [self authenticate]; | |
| } | |
| - (void)didReceiveMemoryWarning { | |
| [super didReceiveMemoryWarning]; | |
| } | |
| - (void)authenticate { | |
| Environment *env = [Environment sharedInstance]; | |
| NSString *apiUrl = env.apiUrl; | |
| NSLog(@"apiUrl = %@", apiUrl); | |
| } | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="UTF-8"?> | |
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
| <plist version="1.0"> | |
| <dict> | |
| <key>Configuration</key> | |
| <string>${CONFIGURATION}</string> | |
| </dict> | |
| </plist> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment