Home > iOS > How to remove unused images from Xcode Project

How to remove unused images from Xcode Project

Most of the times we include many png files in our project and then forget to delete those which are never referenced in our project. You may use following script to find out unsed images in an iOS project

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]'`

for png in `find . -name '*.png'`
do
    name=`basename $png`
    if ! grep -q $name $PROJ; then
        echo "$png is not referenced"
    fi
done

 

You need to save the above script in a file(let’s say ‘myscript’ ) and then follow the below procedure to execute it

  • Go to your Xcode project root folder
  • type “sh myscript”

It’s done. on your screen you will see all the png files which are not referenced in your code.

Note: Beware it will also list the png files which are not referenced in your xib or .m file but are referenced from your sqlite database so make sure you dont delete them.

 

Advertisements
Categories: iOS Tags: , , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: