How to find unused images in an Xcode project?

前端 未结 14 1605
旧时难觅i
旧时难觅i 2020-12-07 06:57

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.)

14条回答
  •  天命终不由人
    2020-12-07 07:39

    Using the other answers, this one is a good example of how to ignore images on two directories and do not search occurrences of the images on the pbxproj or xcassets files (Be careful with the app icon and splash screens). Change the * in the --ignore-dir=*.xcassets to match your directory:

    #!/bin/bash
    
    for i in `find . -not \( -path ./Frameworks -prune \) -not \( -path ./Carthage -prune \) -not \( -path ./Pods -prune \) -name "*.png" -o -name "*.jpg"`; do 
        file=`basename -s .jpg "$i" | xargs basename -s .png | xargs basename -s @2x | xargs basename -s @3x`
        result=`ack -i --ignore-file=ext:pbxproj --ignore-dir=*.xcassets "$file"`
        if [ -z "$result" ]; then
            echo "$i"
        fi
    done
    

提交回复
热议问题