Ios – Xcode5 xcassets – how to bulk replace images

iosxcodexcode5

Say I have a project with 100 images that I've imported into a folder inside the main Images.xcassets file. Then I go and get updates for 67 of those images from my graphics designer – is there an easy way to push those image updates into the xcassets folder?

As it stands, I'm opening the xcassets file in Xcode, and for each of the images that's changed I'm dragging the new image into the little 2x or 1x box – I have to do that 67 times! I can't just drag/drop the files in Finder (the old way) because every image in the xcassets folder has its own subfolder. If I don't use the xcassets file for my images, I can easily update the files by doing this. But xcassets are supposed to "make managing your assets much simpler."

Fine – so what am I missing?

Best Answer

No need for Ruby, you can run this shell script to find files in a origin folder (where your updated images are), find files with the same name in your destination folder (.xcassets folder) and overwrite them with the updated version. Works great!

find ORIGIN FOLDER PATH NAME -name '*.png'  | while read f; do   f2=$(find DESTINATION     FOLDER PATH -name "${f##*/}");   [[ $f2 ]] && cp "$f" "$f2"; done