Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accidentally removed xcassets file from Xcode project

Tags:

xcode

ios

xcasset

I wanted to remove a single folder from the image collection, however, I somehow managed to throw the entire xcassets file into the trash.

The normal 'Put back' method is not available, and simply dragging the deleted folder to Xcode yields an error:

"Images.xcassets" couldn't be copied to "ProjectPear" because an item with the same name already exists.
To save the file, either provide a different name, or move aside or delete the existing file, and try again.

I'm not sure where this collection is located within my Xcode project, as the navigator doesn't appear to show anything, and the command-line isn't dropping any hints either. I'm afraid to mess around with the project.pbxproj file, as it might jumble up a lot more than just my image collection.

Edit: Dragging the files back to Finder from Trash was successful, however, the Xcode navigator no longer recognises - or in this case, still doesn't recognise - the .xcassets file. I'm not sure whether to add something in the .pbxproj file.

like image 665
Aeveus Avatar asked Dec 07 '13 15:12

Aeveus


People also ask

How to Add Asset folder Xcode?

If you don't already have an asset catalog in your project, you can create one by right-click on your project and choosing New File. From "iOS" choose "Resource" then Asset Catalog, then click Next and name your catalog. You can now select your new asset catalog in Xcode, and drag pictures directly into it.

Where is assets Xcassets?

An . xcassets file is, in fact, a folder inside your Xcode project's root folder. Assets are stored in subfolders and metadata is stored in JSON files.


1 Answers

I just did this myself and figured out how to quickly remedy the issue.

  1. Go to the project folder in the Finder. You should find that the folder Images.xcassets is still there.

  2. Move it to a separate location like to the Desktop or something. It still has all of the images and json files.

  3. Jump back to Xcode and create a new asset catalog for images.

    File > New > File... > Resource > Asset Catalog

    Name it Images.

  4. Quit Xcode and return to the Finder.

  5. Copy the folders from within your old Images.xcassets to the new Images.xcassets directory in your project.

  6. Launch Xcode and you're back in business!

like image 127
Jason Barker Avatar answered Sep 20 '22 08:09

Jason Barker