├── README.md
└── find-unused-resources.sh
/README.md:
--------------------------------------------------------------------------------
1 | xcodeutils
2 | -----------
3 |
4 | Some useful utilities to help iOS development
5 |
6 | find-unused-resource.sh
7 |
8 | A small utility which generates a report of unused resources ( .gif, .jpg, .png, .jpeg) in the xcode project. Searches all the source folders( .h, .m) and user interface definitions (.xib, .nib ، .storyboard). This will generate a list of candidates for cleaning up.
9 |
10 | We now support gif,jpg,png,jpeg image File.
11 | We now support .storyboard file
12 |
13 | False positives:
14 |
15 | - Since project.pbxproj is not scaned, there might be false positives on the splash screens used in the project definition.
16 |
- If any resources used runtime in the code like "image_%d", 1 image_1.png is a false positive.
17 |
18 |
19 | How to use
20 | ~~~
21 | $>sh ./find-unused-resources.sh path-to-project > report-name
22 |
23 | ex: find-unused-resources.sh ~/myproject > unused.html
24 | ~~~
25 |
--------------------------------------------------------------------------------
/find-unused-resources.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | #print usual html headers
4 | echo ""
5 | echo " Unused resources
"
6 | #usual disclaimer
7 | echo " Note: This scans all the xib, nib files for the images available. Please look for splash screens or other images carefully in the below list which are used in the project definition (pbxproj file).
In order for links to work the report file must be in the same folder as project."
8 | unusedfiles="";
9 | #initialize the counter
10 | let count=0;
11 | let totalsize=0;
12 | # collect the files needs to be introspected
13 | project=`find $1 -name '*.?ib' -o -name '*.[mh]' -o -name '*.storyboard'`
14 |
15 | for i in `find $1 -name '*.gif' -o -name '*.jpg' -o -name '*.png' -o -name '*.jpeg'`; do
16 | file=`basename -s .jpg "$i" | xargs basename -s .png | xargs basename -s @2x`
17 | if ! grep -q $file $project; then
18 | filesize=`stat -f "%z" $i`;
19 | filesizekb=`echo "$filesize 1024.0" | awk '{printf "%.2f", $1 / $2}'`
20 | unusedfiles="$unusedfiles
$i ($filesizekb kb)";
21 | let "count += 1";
22 | let "totalsize += $filesize"
23 | fi
24 | done
25 | #construct body
26 | totalsizekb=`echo "$totalsize 1024.0" | awk '{printf "%.2f", $1 / $2}'`
27 | echo ""
28 | echo ""
29 | echo "There are $count unused images (total size: $totalsizekb kb)"
30 | echo "
"
31 | echo ""
32 | #generate body content if there are unused files.
33 | if [ $count > 0 ]; then
34 | echo $unusedfiles;
35 | fi
36 | echo "
"
37 | #---------------------------------------------------------------------------------------
38 | # Experimental util to find the source files which are not defined in pbxproj definition.
39 | #---------------------------------------------------------------------------------------
40 | count=0;
41 | unusedfiles="";
42 | project=`find $1 -name '*.pbxproj'`
43 |
44 | for i in `find $1 -name "*.[hmca]" -o -name "*.cpp"`; do
45 | file=`basename "$i"`
46 | if ! grep -q $file $project; then
47 | unusedfiles="$unusedfiles
$i";
48 | let "count = count + 1";
49 | fi
50 | done
51 | echo " Note: This scans all source files (*.h, *.m, *.c, *.a, *.cpp) references in all pbxproj definitions. Once it is added into project definitions, it is considered being used.
"
52 |
53 | echo ""
54 | echo "There are $count unused files"
55 | echo "
"
56 | echo ""
57 | #generate body content if there are unused files.
58 | if [ $count > 0 ]; then
59 | echo $unusedfiles;
60 | fi
61 | echo "
"
62 | echo ""
63 | echo ""
64 | #thats it!
65 |
--------------------------------------------------------------------------------