0

I try to organise the images in XCode Asset Catalog, but I am kind of confused:

(1) I try to create new folders for different group of images. However, I can access an image without specifying the folder name, such as:

let image = UIImage(named: "btn_tabsetting")

Should I give each image a different name even I already have put them in different folders?

(2) As shown below, in test folder, I create an image btn_tabsetting which has the same name as the one in the other folder. Why does XCode allow me to do this? When I call

let image = UIImage(named: "btn_tabsetting")

it actually loads the the one in Tab Setting View folder instead of the one in test folder, why is it so? What is the rule here?

I think maybe I misunderstand some important concepts in using the Asset Catalog, please help me to correct them.

enter image description here

Joe Huang
  • 6,296
  • 7
  • 48
  • 81
  • XCode uses groups and not folders. Read here about difference http://stackoverflow.com/questions/8851144/explanation-of-xcode-settings-for-folders-added-to-project – tbilopavlovic Jun 13 '16 at 12:25
  • 1
    @user1941284 I know difference in folders and groups and I am doing fine with them, but I think Asset Catalog has arranged things differently. – Joe Huang Jun 13 '16 at 12:34

2 Answers2

2

According to docs

For any target in an Xcode project, the fully qualified name of an asset must be unique across all the asset catalogs and across all asset types. For example, it is an error to have an image set folder in one asset catalog called Llama.imageset and an image set with the same name in the same catalog or in a different catalog that is part of the same target. Similarly, it is an error to have both an image set folder called Llama.imageset and an app icon folder called Llama.appiconset in the same catalog or in a different catalog that is part of the same target.

So asset names should be unique. What I recommend is organize assets in logical groups and than prefixing each asset inside group with group name. For an example:

- Icons (group)
    - icon_gear
    - icon_heart
    - icon_edit
    - TabBar (group)
        - icon_tabbar_profile
        - icon_tabbar_settings
    - Settings (group)
        - icon_settings_age
        - icon_settings_name
- Streachables (group)
    - streachable_profile_background
    - streachable_product_background
Kubba
  • 3,390
  • 19
  • 34
-1

Xcode Automatically set different image name, if you have placed same name of images in Asset Catlog.

Suppose i have drop one image as xyz.png and then i again drop xyz.png in it, the xcode will rename it with xyz_1.png

Khushboo Motwani
  • 205
  • 3
  • 12
  • I think `btn_tabsetting` in my example is not image file name. Your answer doesn't answer my question either. – Joe Huang Jun 13 '16 at 12:32