An open API service indexing awesome lists of open source software.

https://github.com/michaelnisi/refuse

CLI tool that finds unused visual assets in Xcode projects 🛠️🗑️
https://github.com/michaelnisi/refuse

xcode

Last synced: 15 days ago
JSON representation

CLI tool that finds unused visual assets in Xcode projects 🛠️🗑️

Awesome Lists containing this project

README

          

# refuse

A Swift CLI tool that finds unused visual assets in Xcode projects.

## What it does

`refuse` scans an Xcode project or workspace for `.xcassets` catalogs, collects all image, color, and symbol assets, then parses Swift source files to find which assets are never referenced anywhere. It understands both string literal references (`UIImage(named: "my_icon")`) and generated resource identifier references (`Image(.myIcon)`).

Built for large multi-target apps — the Swift source corpus is parsed concurrently.

## Installation

```sh
git clone https://github.com/michaelnisi/refuse
cd refuse
swift build -c release
sudo cp .build/release/refuse /usr/local/bin/refuse
```

## Usage

Run from your project root:

```sh
refuse
```

Or pass a path explicitly:

```sh
refuse /path/to/MyApp
```

To delete unused assets after confirmation:

```sh
refuse -d
```

## Output

Progress is written to stderr, results to stdout:

```
Found 1247 assets across 8 catalogs
Scanning 342 Swift files...

Colors.xcassets (1)
deprecated_red colorset

Icons.xcassets (2)
another_unused imageset
unused_symbol symbolset

3 unused assets across 2 catalogs
```

## CI

`refuse` exits with code `1` when unused assets are found, `0` when the project is clean. Use `-s` to suppress progress output while keeping error messages visible:

```sh
refuse -s
```

## Limitations

- Only Swift source files are scanned. Objective-C and Interface Builder files are not.
- Font assets (`.fontset`) are not supported — fonts are referenced by PostScript name, not asset name.
- Assets referenced via computed strings or loaded from remote config will be reported as unused.
- Generated resource identifiers (e.g. `.myIcon`) are only recognised when passed directly as a call argument. Assets accessed via a variable or intermediate expression will be reported as unused.