Sometimes we need to be more generic about naming convention of images. We may need same name of assets(images) for various views.
Xcode doesn’t allow us to keep the files with same name and can throw error or change the asset name by itself.
In that case we have an option to overcome this situation by using “Provide NameSpace” option provided at the right panel (attribute inspector) which will create assets subdirectories.
Here are the Steps to use “Provide NameSpace”:
1- Click on xcassets catalog.
2- Create a folder using “+” button provided at the bottom (see screen shot below)
3- Drag all the image to the folder
you can achieve 2nd and 3rd by selecting the images to be grouped and then select “New Folder from selection” from the option as annotated in screenshot. It will create a new folder having selected images.
4- Now you’ve all the images in your custom folder. Now select the folder and on the attribute inspector check “provide namespace”.
Now all the images are grouped and you can create new folder( proceeded by same steps as above) so that images with same name can be kept in assets (see attached screenshot).. These are actually very similar to “having subdirectories in bundle”
For accessing the images you have to use name like “FolderName/ImageName”
Example from above steps: YourSecondFolder/imageOne
Thank You
0 Comment(s)