Skip to content

joeboyscout04/AssetChecker

ย 
ย 

Repository files navigation

Localize

AssetChecker

Language: Swift Platform: iOS codebeat badge License: MIT GitHub tag

AssetChecker is a tiny run script that keeps your Assets.xcassets files clean and emits warnings when something is suspicious.

AssetChecker

Because Image Assets files are not safe, if an asset is ever deleted, nothing will warn you that an image is broken in your code.

Try it!

AssetChecker is part of freshOS iOS toolset. Try it in an example App ! Download Starter Project

What

By using a script running automatically, you have a safety net that makes using Asset Catalog a breeze.

How

The script will automatically find the asset catalogs ( .xcassets) in your project and serarch your source code to determine if there are errors with them. It searches for the following types of files:

  • xibs
  • storyboards
  • swift files
  • Obj-C (.m) files

For these types of references:

  • #imageLiteral(resourceName: )
  • UIImage(named: ) (swift)
  • [UIImage imageNamed: ] (ObjC)
  • R.image.name() (supports R.Swift)

Then the script will automatically (On build)

  • Raise Errors for Missing Assets
  • Raise warnings for Unused Assets

Installation

Cocoapods

Installation available via Cocoapods. Add the following to your Podfile:

pod 'AssetChecker'

Add the following Run Script in XCode, this will run the script at every build. If you installed via Cocoapods, you can use the following script:

${PODS_ROOT}/AssetChecker/run
$ mint install github_name/repo_name

Add the following Run Script in XCode, this will run the script at every build.

mint run assetchecker

Manually

You can also just clone this package into your Xcode repository, then drag the this folder into your Xcode project. This will create a reference to AssetChecker's swift package.

Add the following Run Script in XCode, this will run the script at every build.

/usr/bin/xcrun --sdk macosx swift run path/to/assetchecker

Script Arguments

The following command line arguments are available to the script.

--catalog (optional) Path to your asset catalog.  By default, it will search all asset catalogs in your $SRCROOT
--source (optional) Absolute path to your source directory.  Defaults to $SRCROOT
--ignore (optional) A comma-separated list of assets which should be ignored by the script (no file extension needed)
--ignoreFile (optional) Path to the ignore file.  If this option is used, --ignore option will be ignored.  By default, $SRCROOT/.assetcheckerignore.

Ignore file

You can add names of assets to ignore to a .assetcheckerignore file at the root of your project. Put the name of each asset to ignore on a separate line, without any path or file extension. Regex values are also accepted.

False positives

Sometimes you're building the asset names dynamically so there is no way for AssetChecker to find out statically by looking at the codebase.

In this case the script will emit a false positive.

You can manually declare these false positives so that they get ignored by using the --ignore command line option mentioned above.

Author

Sacha Durand Saint Omer, [email protected]

Contributing

Contributions to AssetChecker are very welcomed and encouraged!

License

AssetChecker is available under the MIT license. See LICENSE for more information.

Backers

Like the project? Offer coffee or support us with a monthly donation and help us continue our activities :)

Sponsors

Become a sponsor and get your logo on our README on Github with a link to your site :)

About

๐Ÿ‘ฎ Asset Catalogs just got better

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 93.6%
  • Ruby 6.4%