Thursday 3 January 2013

Configuring Environment Variables iOS

Say you've got an iOS app talking to a backend api. Maybe this api runs as localhost on your machine when you're in development and maybe you also have staging and production environments out in the cloud somewhere. What's the best way to set this up?

I've gone with an encapsulated pList... setup as follows.

This is my pList file.
I encapsulate that in a class called EnvironmentVars.

After which, I can access it as follows from anywhere. This is an example of using it to create a NSUrl object.
Objective C code can be terse. I find it's best to exercise encapsulation to the extremist point to maintain sanity.

No comments:

Post a Comment