Search code examples
xcodeios5run-script

How to write a Run Script in Xcode


In my project i have Frameworks different for iPhone Simulator and iPhone Device for example like in Rest kit "libRestKit_simulator.a" for simulator and "libRestKit.a" for device,

My requirement is to write a "Run Script" in Xcode to include the frameworks based on the Simulator or device.


Solution

  • Not sure if this is the best solution but it appears to work for me.

    If you add a build script below target dependancies then add in the following code. This assumes you have 2 libraries

    1. library.a
    2. library_simulator.a

    The project would be set up to use library.a and if you are using the simulator the script will remove library.a and replace it with library_simulator.a. You would need to add the simulator to your build scheme to make sure it is built when doing a build and both libraries would need the same interface.

    if [[ "${SDKROOT}" == *Simulator* ]]
    then
    
        if [[ -f "${BUILT_PRODUCTS_DIR}/library.a"]]
        then
            rm -rf "${BUILT_PRODUCTS_DIR}/library.a"
        fi
    
        mv "${BUILT_PRODUCTS_DIR}/library_simulator.a" "${BUILT_PRODUCTS_DIR}/library.a"
    fi
    

    Not sure how much use this is to you, I only tested it briefly. Hope it helps.