xcodeassets

How to find unused images in an Xcode project?


Has anyone a one-line to find unused images in an Xcode project? (Assuming all the files are referenced by name in code or the project files - no code generated file names.)

These files tend to build up over the life of a project and it can be hard to tell if it's safe to delete any given png.


Solution

  • For files which are not included in project, but just hang-around in the folder, you can press

    cmd ⌘ + alt ⌥ + A

    and they won't be grayed out.

    For files which are not referenced neither in xib nor in code, something like this might work:

    #!/bin/sh
    PROJ=`find . -name '*.xib' -o -name '*.[mh]'`
    
    find . -iname '*.png' | while read png
    do
        name=`basename $png`
        if ! grep -qhs "$name" "$PROJ"; then
            echo "$png is not referenced"
        fi
    done