FengNiao

A command line tool for cleaning unused resources in Xcode.

Github星跟踪图

What

FengNiao is a simple command-line util to deleting unused image resource files from your Xcode project.

How

Install

You need Swift Package Manager (as well as swift compiler) installed in your macOS; generally you are prepared if you have the latest Xcode installed.

Compile from source

> git clone https://github.com/onevcat/FengNiao.git
> cd FengNiao
> ./install.sh

FengNiao should be compiled, tested and installed into the /usr/local/bin.

Homebrew

You may want to install in from Homebrew. But for now it is not supported.

Usage

Just navigate to your project folder, then:

> fengniao

It will scan current folder and all its subfolders to find unused images, then ask you whether you want to delete them. Please make sure you have a backup or a version control system before you deleting the images; it will be an un-restorable operation.

FengNiao supports some arguments. You can find it by:

> fengniao --help

  -p, --project:
      Root path of your Xcode project. Default is current folder.
  --force:
      Delete the found unused files without asking.
  -e, --exclude:
      Exclude paths from search.
  -r, --resource-extensions:
      Resource file extensions need to be searched. Default is 'imageset jpg png gif pdf'
  -f, --file-extensions:
      In which types of files we should search for resource usage. Default is 'm mm swift xib storyboard'
  --version:
      Print version.
  -h, --help:
      Print this help message.

A more daily-work usage under a project could be:

> fengniao --project . --exclude Carthage Pods

This will search in current folder, but skip the Carthage and Pods folder, in which there might be some third party resources you do not want to touch.

Use with Xcode build phase

It is easy to integrate FengNiao into your Xcode build process. By doing so, you could ensure your project being cleaned every time you build your project.

Add a "Run Script" phase in the Build Phases tab:

Then drag it above of "Copy Bundle Resources", editing its content to something like this:

fengniao --exclude Carthage --force

It is recommended to exclude vendor's folders like Pods or Carthage. Since you do not have a chance to confirm the result, you also need to add --force option.

How it works

  1. Extract resource file names (default file type: ["imageset", "jpg", "png", "gif", "pdf"]) in these folders ["imageset", "launchimage", "appiconset", "bundle”].
  2. Use regular expression to search all string names in files (default files type: ["m", "mm", "swift", "xib", "storyboard", "plist"]).
  3. Exclude all used string names from resources files, we get all unused resources files.

License and Information

FengNiao is open-sourced as MIT license. The name of this project comes from the Chinese word 蜂鸟 (hummingbird), which is the smallest bird in the world.

Submit an issue if you find something wrong. Pull requests are warmly welcome, but I suggest to discuss first.

You can also follow and contact me on Twitter or Sina Weibo.

Learning to Create

I streamed the way I created this tool as a live-coding session in a live platform in China. You can learn how to create a project with Swift Package Manager, how to apply Protocol-Oriented Programming (POP) in the project, and how to develop in a BDD way as well as write good tests there.

It is a paid series lesson in Chinese. If you are interested in it, please check and watch the links below:

现场编程 - 用 Swift 创建命令行工具 fengniao-cli

主要指标

概览
名称与所有者onevcat/FengNiao
主编程语言Swift
编程语言Swift (语言数: 3)
平台
许可证MIT License
所有者活动
创建于2017-03-07 02:20:20
推送于2025-04-22 15:12:05
最后一次提交2025-04-23 00:12:05
发布数15
最新版本名称0.9.0 (发布于 2024-01-09 21:22:45)
第一版名称0.1.0 (发布于 )
用户参与
星数3.5k
关注者数51
派生数233
提交数127
已启用问题?
问题数50
打开的问题数26
拉请求数26
打开的拉请求数1
关闭的拉请求数3
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?