0

The naming convention I refer is not the naming rules for different devices, like suffix of @2x and @3x. Here I want to seek a better naming conversion for better legibility.

For example:

There is an icon for setting button , and I will name it icon_setting@2x.png which may run into collisions if there is another setting icon with different style in other view controller A. To solve this, I may name it A_icon_setting and it will lead to a long name if A is long.

So I am always struggling naming a image in my iOS development and I wonder what is a good name conversion for iOS image resource.

Jamie
  • 9
  • 1
  • 2
  • 1
    http://www.wastedpotential.com/image-naming-conventions-for-ios-and-android-apps/ – Rohit Khandelwal Jan 06 '16 at 05:30
  • I dont think u have to be struggling with this for anything really :) for me i ussually just name it `setting@2x.png` and put it in group A since .xcassets can great group inside it, A can be shorterned ofc, what's the point of write the whole `AViewController` word, anything simple and easy refering is cool – Tj3n Jan 06 '16 at 05:30
  • @Tj3n Writing the whole `AViewController` is to avoid collisions. So you put vc and image resources, (e.g. `.xcassets`) in a same group? – Jamie Jan 06 '16 at 05:36
  • Hm..There can never be 2 VC with same name, if its for something other than that (eg.`ATableViewCell`) then i set the group name `ACell`...something like that :D And no im only using 1 `.xcassets` folder, but i create many group inside it by pressing `+` below, so u can safely grouping your image without need to name them very long – Tj3n Jan 06 '16 at 05:41
  • @Dev.RK Thanks. A good guide. – Jamie Jan 06 '16 at 05:41
  • @Jamie please make comment as useful by clicking up arrow, So that other user can take benefit of that.Thanks – Rohit Khandelwal Jan 06 '16 at 05:44
  • @Tj3n I got you. Creating group in `.xcassets ` is a great way to ease my struggling. – Jamie Jan 06 '16 at 05:48
  • @Dev.RK Okay, however I'm afraid I don't have enough reputation to do that. – Jamie Jan 06 '16 at 05:51
  • @Jamie Glad to help :D – Tj3n Jan 06 '16 at 05:51

1 Answers1

1

Why use Snake Case? I would claim it is more common among iOS developers to use lower camel case: viewDisabledBackground.

I would definitely use an Asset Catalog to organize your images. The nice thing about using a catalog is that the name of the individual images doesn't matter. You just need to slot each image size into the corresponding image well, and give the asset itself an appropriate name. For eligibility you could even consider including spaces when naming images in an Asset Catalog (.xcassets).

The following might be helpful when naming an asset:


Increase Freedom with Folders

Each Folder in an Asset Catalog can be configured to create a name space, allowing you to reuse short names across folders. This gives you a lot of freedom, and will allow you to keep your image names consistent and short. How to set up folders with name spaces, and how to reference the images in your code: https://stackoverflow.com/a/33285214/84682


Use Common Sense

How to best name your assets is obviously a matter of opinion, yet here are some of my common sense guidelines you could consider when naming:

  • Avoid descriptors that might become outdated; like where or how something is used: topLeftCloseButtonIcon and LoginCancelButton are both bad because the button may move or used by something other than login.

  • Generally use descriptors that makes sense to your entire team: don't call it blueRhombus if blueSquare will do.

  • Append expert descriptors to more familiar terms; chairFancyRococo.

Community
  • 1
  • 1
Johan
  • 2,472
  • 1
  • 23
  • 25