Search code examples
xcodexcode4

Is there any way to override build settings per person in Xcode?


I'm working on an iPhone app which connects to several services via REST API.

There are some servers for each service(development, production, etc), and I want to switch these servers to connect by compiler flags WITHOUT modifying foo.xcodeproj/project.pbxproj.

I'm in a team of 6 developers and each person wants to connect to different servers combination, but it will be a mess if I include these configuration in project.pbxproj which is managed by git.

So I need to change compiler flags with a file which is not managed by git.

Ideally, I want local settings mechanism like in Django. Is there any ways to do this with Xcode?

Thanks! Any advice is highly appreciated.


Solution

  • Having your compiler flags not under source control is a huge RED FLAG. How can you guarantee consistent building of your app. // End Soap Box

    Answer

    I would create a user defined build setting for the production and dev servers. And a run script to set the server to use in the application info.plist

    • Add build setting REST_Server

    enter image description here
    enter image description here

    • Add run script to update the info.plist

    enter image description here
    enter image description here

    # ---------------------------- IMPORTANT ----------------------------
    # You must set RESTServer to something like 'Set by build script' in the file
    # file '<Project Name>-Info.plist' in the 'Supporting Files' group
    # -------------------------------------------------------------------
    #
    # determin server based on user name
    #
    
    SERVER=${REST_Server}
    
    # Only use developer servers for debug never for release
    if [ "$CONFIGURATION" != "Debug" ] ; then
        exit
    fi
    
    if [ "$USER" == "gdunham" ] ; then
        SERVER="gld.nextbigthing.com"
    fi
    
    if [ "$USER" == "jashmun" ] ; then
        SERVER="jda.nextbigthing.com"
    fi
    
    echo $SERVER
    
    #
    # Set the server info in plist file in the build product not the source tree
    #
    /usr/libexec/PlistBuddy -c "Set :RESTServer $SERVER" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
    
    • Add place holder to info.plist

    enter image description here

    For all the gory details see my demo project on GitHub https://github.com/GayleDDS/DemoMultiDeveloper