Referencing image in a folder in asset catalog Referencing image in a folder in asset catalog ios ios

Referencing image in a folder in asset catalog

Visual Instructions

(based on Xcode 10.1)

To have the path uniquely identify an asset catalog image, set the "Provides Namespace" attribute of the folder to true.

1) Select the asset catalog folder.

enter image description here

*The folder is yellow if "Provides Namespace" is false.

2) Make sure the Inspectors panel is visible

enter image description here

3) In the Inspectors panel, select the Attributes Inspector. Check the "Provides Namespace" checkbox.

enter image description here

Notice that the folder icon turns blue indicating that "Provides Namespace" is true.

enter image description here

When referencing the image in code, remember to include the namespace.

let image = UIImage(named: "Icon/Menu")

I spent a ton of time but finally figured this out. Answered here. Copied below.

Select each folder in your asset catalog that you'd like to add a namespace for. Go to the folder attributes and select under the name "Provides Namespace". This should properly set sub-directories for your final asset catalog.

You can do this manually by editing each folder's Contents.json. You would add the following with proper formatting.

"properties" : {      "provides-namespace" : true}