r/iOSProgramming • u/iahmedhendi • 24d ago
Library I scanned 10 open-source iOS apps for unused images and strings. Firefox bundles a 5.72 MB GIF nothing loads.
When a feature goes away, its art and strings often stay. Xcode never warns about an image set nobody names, so it ships in every build.
I wrote a CLI to find these and tested it on 10 open-source apps, read-only. Three findings stood out. I checked each one with grep across the whole repo:
- firefox-ios:
kitHeroGif.gif, 5.72 MB. It is listed inproject.pbxproj, so it gets copied into the bundle. The app's only GIF loader is called with a different name. - Kickstarter ios-oss:
landing-backgroundandlanding-page-background, each in three asset catalogs. 12.63 MB of source files, 0 references. - wikipedia-ios: three GIFs next to the year-in-review art, 5.62 MB, 0 references.
These are source sizes. I did not measure the shipped apps, and compiled catalogs can change the saving.
Many smaller findings are stale strings: keys that only exist in translated .lproj files, or SwiftGen accessors that nothing calls.
How I use it on my own code:
xcpurge scan . --format html --open
xcpurge explain . SOME-ID
xcpurge remove . PATH
xcpurge purge . --dry-run
xcpurge restore .It reads files and does not build, so a scan takes seconds. Each finding is high, medium or low confidence. remove moves files to a trash folder in the project and edits project.pbxproj. purge does that for every actionable finding in one run, or for the ids you tick in the HTML report. restore undoes it all.
Where it is wrong. On the first run only 26 of 50 hand-checked high findings were real. Snapshot test images and names used from another module were the big causes. Over three runs it went from 52% to 92% to 96%: 48 of 50, and 48 of 50 again on a second sample. Known limits:
- names built from two interpolations, like
"\(base)-\(lang)"(16 Lottie files in Kickstarter, 18.8 MB, still reported high) - keys used only inside a multiline
Text("""…""")literal - names that come from a server or a package outside the repo
So treat high as "nothing in the repo names it", not as "safe to delete blind".
Free and MIT, macOS, version 0.6.0 (brew install iasaeed/tap/xcpurge). Feedback on false positives is the most useful thing you could send.
13
u/LostStrategy1050 24d ago
Now do the CVS app. it's 700mb+. Their IRL receipts are nothing compared to their app
2
u/cristi_baluta 24d ago
Names could be built at runtime from multiple parts.
1
u/Miserable-Carpet7928 24d ago
can i mark a reviewed finding as 'keep' with a short reason, and have that survive the next scan? for something named by the server, that decision lives outside what a repo search can prove. keeping the explanation beside the finding would save repeating the same investigation.
1
u/kokerali 24d ago
I read Restore.swift: .moved skips an existing destination, but .rewritten removes it before copying the backup. Could restore refuse the latter when the current file differs from the post-cleanup version, unless explicitly forced?
A useful fixture would be: remove one asset, add an unrelated build setting in Xcode, then restore. I'd expect the newer setting to survive, or a clear conflict with the trash session retained, rather than silently returning the entire project file to its older state. I haven't run that sequence; this is from the restore code. Does a guard elsewhere already cover it?
1
u/KukrCZ 24d ago
The thing with huge projects is that usually there are for example dozens of teams owning parts of the app. They have their budgets. Usually features are added, nodified and removed and nobody wants to pay extra for the app cleanup.
Usually you would associate technical debt with code directly, but it is also in assets and localisations also.
To rempve any kind of texhnical debt you need to have time and money.
1
u/lefinehq 23d ago
careful with the keys that only exist in translated .lproj files. A lot of those are renames, not dead strings: the base key got renamed, the translations kept the old name, and now the "unused" German value is the only translation of a string that's live. Pairing each orphan with base keys that are missing in that same language would let people move the translation instead of deleting it
1
u/dawedev 23d ago
Snapshot test images being the top false positive makes sense, since those usually sit under a test target. Treating anything only referenced from a test bundle as its own category by default might clear most of them. Another case I'd check is alternate app icons: they're listed under CFBundleAlternateIcons in Info.plist and loaded by name through setAlternateIconName, so they look unused from Swift code. Same with images referenced only from storyboard or xib image attributes and the launch screen.
4
u/[deleted] 24d ago
[removed] — view removed comment