Shell script for genrating XCAssets for Projects

Hi All ! In this post, you’ll find a script. This shell script is going to help you to generate XCAssets.

Why do we need XCAssets?

In earlier XCode5, we’re forced to (or it is more preferable to) manage assets/images of the project using XCAssets. For example have a quick look into following snap-shot

Shell script for genrating XCAssets for Projects

So, XCAssets provide us more simpler way to manage assets of project. But what are the challanges

  • We have to create first image-sets.
  • Move image-sets into appropriate folder as per convenience
  • Set name for the image-set
  • Set name for 1x image as per given to the name of image-set (more preferable for supporting older iOS)
  • Set name for 2x image as per given to the name of image-set (more preferable for supporting older iOS)
  • Make sure 1x image is exactly half than the 2x image.
  • So, as a developer, we have to ask designer to provide images in both dimensions. If designer is lazy in giving appropriate name, we as a developer have to set the name of ‘image-set’, ‘image1x’ & ‘image2x’. which literally indicates a laborious job as a project may have number of images.

So, I tried to eliminate this laborious job with a shell-script.

What you have need to do before executing following script?

  1. Please read post very carefully & don’t start executing script.
  2. Get the sliced images from the designer.
  3. Make sure you’ve all images for retina resolution.
  4. If files are not as per the naming convention – having suffix of @2x.png, please apply @2x.png to all files <= this is very important for correct output of shell-script.
  5. Make appropriate folders & move images into folders as per convenience. ALERTPlease do not add space to files or folders or any special characters. I’m not shell-script expert & couldn’t manage such in file-folders
  6. Here is an example directory structure, how it should look like. Make sure you’ve similar pattern in your directory structure.
  7. Shell script for genrating XCAssets for Projects 2
  8. Open terminal & make sure your working directory is root directory of your-design folder. Here in this case ‘Login’ is the root folder.
  9. Save following script & execute it by suffixing ‘sudo’ – here is the example screen-shot.
  10. Shell script for genrating XCAssets for Projects 3


Here is the example screen-shot of output.

Shell script for genrating XCAssets for Projects 4

Now copy directory under your projects.xcassets directory & You’ll find all assets managed properly as follows.

Shell script for genrating XCAssets for Projects

Leave a Reply

Your email address will not be published. Required fields are marked *



*