Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Rake task to clean unused images in your iOS project
desc 'Remove unused images'
task :clean_assets do
require 'set'
all =
used =
unused =
# White list
used.merge %w{Icon Icon-29 Icon-50 Icon-58 Icon-72 Icon-114}
regex = /\[UIImage imageNamed:@"([a-zA-Z0-9\-_]+).png"\]/
Dir.glob('Classes/*.m').each do |path|
Dir.glob('Resources/Images/*.png').each do |path|
next if path.include? '@2x.png'
all << path.gsub('Resources/Images/', '').gsub('.png', '') # My regex skills need work
unused = all - used
unused.each do |key|
`rm -f Resources/Images/#{key}.png Resources/Images/#{key}@2x.png`
puts "#{all.length} total found"
puts "#{used.length} used found"
puts "#{unused.length} deleted"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.