A command line tool for cleaning unused resources in Xcode.

Overview

FengNiao

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

Comments
  • Swift 5.0 suport

    Swift 5.0 suport

    image

    喵神您好,我打开项目源码,发现无法编译通过,原因是: CommandLineKit、CommandLinePackageDescription、PathKit 这三个库使用的时 Swift 3 image 导致此插件无法通过编译,希望您能帮助我解决这个问题,谢谢。 对了,我的Xcode版本yi以及macOS系统版本如下 image image

    opened by MrBugDou 7
  • Deleting files with used pngs too

    Deleting files with used pngs too

    it shows me that how many unused files are there in my project, but it also contains files which are used. And once I run the command , all the respective unused image becomes red files. Maybe its only removing its reference. Plz help.

    opened by fatinWasta 6
  • remove the image reference in project.pbxproj

    remove the image reference in project.pbxproj

    some projects drag the images into the project ,so the xcodeproj has the reference of the images . when run the fengniao command line tool ,the images are deleted ,but in the project , the build will failed . we should remove images by hand

    opened by KyleRuan 3
  • Swift 5 support issue

    Swift 5 support issue

    The targets “PathKit” and “CommandLineKit” contains source code developed with Swift 3.x. This version of Xcode does not support building or migrating Swift 3.x targets.

    Use Xcode 10.1 to migrate the code to Swift 4. 我的Xcode 版本是 10.2.1 (10E1001), 希望有时间能兼容最新的Swift版本,非常感谢!

    opened by 913868456 2
  • dyld: Symbol not found

    dyld: Symbol not found

    When trying to find unused resources using FengNiao I get this output in console dyld: Symbol not found: __T0s11CommandLineO9argumentsSaySSGvZ Referenced from: /usr/local/bin/fengniao Expected in: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/libswiftCore.dylib in /usr/local/bin/fengniao Abort trap: 6 I think it has something to do with Swift 4.1 and Xcode 9.3.

    opened by MaxAdamyan 2
  • The README bottom video links can't play

    The README bottom video links can't play

    Hi, I was clicked the bottom video links, and then I payed the money in the Wechat to see the playback. But after payed, I still can't played the video(The error info can see the screenshot image),mobile is same. So I don't konw how to do can make see the videos. Can you help me? Thanks !

    Part1

    7969f8c3-9578-4621-aac1-1c3acf2e11b4

    opened by huaqixue 2
  • xcrun: error: unable to find utility

    xcrun: error: unable to find utility "xctest", not a developer tool or in PATH

    environment:macOS Catalina 10.15,Xcode 11.1 (11A1027)

    error: terminated(72): xcrun --sdk macosx --find xctest output: xcrun: error: unable to find utility "xctest", not a developer tool or in PATH

    error: terminated(72): xcrun --sdk macosx --find xctest output: xcrun: error: unable to find utility "xctest", not a developer tool or in PATH

    error: terminated(72): xcrun --sdk macosx --find xctest output: xcrun: error: unable to find utility "xctest", not a developer tool or in PATH

    cp: .build/release/FengNiao: No such file or directory

    opened by Deyupy 1
  • Doesn't delete files from Copy Bundle Resources

    Doesn't delete files from Copy Bundle Resources

    I have plenty PNG-files just as files included in Bundle. Tool successfully deleted unused ones, but records in target's Copy Bundle Resources stayed untouched. I had to delete them manually to make the project built.

    opened by lazarevzubov 1
  • Add .pdf file support

    Add .pdf file support

    • Add to PDF file support as default
      • image set support pdf, and PDF file is very useful for using vector image in iOS.
        • https://developer.apple.com/library/archive/documentation/Xcode/Reference/xcode_ref-Asset_Catalog_Format/ImageSetType.html
    opened by yanamura 1
  • Error: no such module 'PackageDescription' M1 Pro

    Error: no such module 'PackageDescription' M1 Pro

    Hey guys, I'm getting this error installing FengNiao in a MacBook Pro 2021 with M1 Pro.

    With HomeBrew and Mint

    error: no such module 'PackageDescription'
    import PackageDescription
           ^
    

    Compiled Manually with Verbose

    error: 'fengniao': Invalid manifest
    <unknown>:0: remark: did not find a prebuilt standard library for target 'arm64-apple-macos' compatible with this Swift compiler; building it may take a few minutes, but it should only happen once for this combination of compiler and target
    /Users/carlos.lopez/Development/FengNiao/[email protected]:3:8: error: no such module 'PackageDescription'
    import PackageDescription
           ^
    

    Any help?

    opened by callo90 0
  • Add option to print results as xcode warnings for build phases

    Add option to print results as xcode warnings for build phases

    Add support for usage in Xcode build phases. Xcode uses the following format for log warnigs: path/to.file: severity: error message

    Usage:

    path/to/fengniao --project . --xcode-warnings
    

    Don't fail build phase with warnings:

    path/to/fengniao --project . --xcode-warnings || true
    
    opened by voidless 0
  • Link is not valid anymore

    Link is not valid anymore

    Hi,

    Appreciate your work. It seems README's learning video link is not valid anymore, I really enjoy watching your video and it helps me a lot. please update if you have any other video link.

    Thanks for your work again!🙌🏻

    https://github.com/onevcat/FengNiao#learning-to-create

    opened by tzxdtc 0
Releases(0.8.1)
Owner
Wei Wang
Developer, creator, proud father.
Wei Wang
An adorable little framework and command line tool for interacting with SourceKit.

SourceKitten An adorable little framework and command line tool for interacting with SourceKit. SourceKitten links and communicates with sourcekitd.fr

JP Simard 2.1k Jan 5, 2023
Strong typed, autocompleted resources like images, fonts and segues in Swift projects

R.swift Get strong typed, autocompleted resources like images, fonts and segues in Swift projects Why use this? It makes your code that uses resources

Mathijs Kadijk 8.9k Jan 6, 2023
Xcode storyboards diff and merge tool.

StoryboardMerge Storyboard diff and merge tool which: compares and merges two storyboard files, provides an automatic merge-facility, The storyboardin

null 238 Sep 12, 2022
Xcode-compatible build tool.

xcbuild xcbuild is an Xcode-compatible build tool with the goal of providing faster builds, better documentation of the build process and running on m

Meta Archive 2k Dec 11, 2022
Automatically build and rebuild Xcode image catalogs for app icons, universal images, and more

Better asset workflow for iOS developers. Generate Xcode image catalogs for iOS / OSX app icons, universal images, and more.

Dotan J. Nahum 822 Dec 21, 2022
Xcode .appiconset generator for Adobe Illustrator.

Creating AppIcon sets from Adobe Illustrator This repo is rewrited from original repo https://github.com/CaryChamplin/CreatingIconsFromAI. Just genera

gitmerge 73 Nov 9, 2020
Script to support easily using Xcode Asset Catalog in Swift.

Misen Misen is a script to support using Xcode Asset Catalog in Swift. Features Misen scans sub-directories in the specified Asset Catalog and creates

Kazunobu Tasaka 123 Jun 29, 2022
A git plugin for real-world xcode versioning workflow.

git-xcp The most simplest, safe, and fully automatic git plugin for versioning workflow of real-world xcode projects. Current working or draft content

gitmerge 11 Dec 29, 2019
An Xcode plug-in to format your code using SwiftLint.

SwiftLintXcode An Xcode plug-in to format your code using SwiftLint. Runs swiftlint autocorrect --path CURRENT_FILE before *.swift file is saved. IMPO

Yuya Tanaka 348 Sep 18, 2022
An Xcode Plugin to convert Objective-C to Swift

XCSwiftr Convert Objective-C code into Swift from within Xcode. This plugin uses the Java applet of objc2swift to do the conversion. Noticed that the

Ignacio Romero Zurbuchen 338 Nov 29, 2022
An executable that can be called from a Run Script Build Phase that makes comments such as // TODO: or // SERIOUS: appear in Xcode's Issue Navigator giving them project-wide visibility.

XcodeIssueGenerator An executable that can be called from a Run Script Build Phase that makes comments such as // TODO: or // SERIOUS: appear in Xcode

Wunderman Thompson Apps 143 Oct 11, 2022
This repository contains rules for Bazel that can be used to generate Xcode projects

rules_xcodeproj This repository contains rules for Bazel that can be used to generate Xcode projects. If you run into any problems with these rules, p

BuildBuddy 233 Dec 28, 2022
Command line tool for exporting resources and generating code from your Figma files

Fugen Fugen is a command line tool for exporting resources and generating code from your Figma files. Currently, Fugen supports the following entities

Almaz Ibragimov 69 Dec 17, 2022
Command line program that detects unused resource strings in an iOS or OS X application.

Abandoned Resource String Detection This command line program detects unused resource strings in an iOS or OS X application. Updated to Swift 3, thank

Josh Smith 360 Nov 26, 2022
Synx - A command-line tool that reorganizes your Xcode project folder to match your Xcode groups

A command-line tool that reorganizes your Xcode project folder to match your Xcode groups. Xcode Finder Installation $ gem install synx Usage Basic ⚠

Venmo 6.1k Jan 2, 2023
A Swift command line tool for generating your Xcode project

XcodeGen XcodeGen is a command line tool written in Swift that generates your Xcode project using your folder structure and a project spec. The projec

Yonas Kolb 5.9k Jan 9, 2023
A command-line tool and Xcode Extension for formatting Swift code

Table of Contents What? Why? How? Command-line tool Xcode source editor extension Xcode build phase Via Applescript VSCode plugin Sublime Text plugin

Nick Lockwood 6.3k Jan 8, 2023
The best command-line tool to install and switch between multiple versions of Xcode.

The best command-line tool to install and switch between multiple versions of Xcode.

Robots and Pencils 2.3k Jan 9, 2023
A command-line tool to generate a JSON-list of all used SPM-dependencies of an Xcode-project.

SwiftPackageList A command-line tool to generate a JSON-list of all used SPM-dependencies of an Xcode-project. This includes all the Package.resolved

Felix Herrmann 14 Jan 8, 2023
A command-line tool to sort Xcode's `.xcodeproj` file.

XcodeProjSorter A command-line tool to sort Xcode's .xcodeproj file. It sorts following sessions: PBXGroup PBXResourcesBuildPhase PBXSourcesBuildPhase

Nelson 7 Apr 27, 2022