Accidentally deleted xcassets file from Xcode project

I wanted to delete one folder from the image collection, but somehow I managed to throw the whole xcassets file into the trash.

The usual “Return” method is not available, and simply dragging and dropping a remote folder into Xcode will result in an error:

Images.xcassets could not be copied to ProjectPear because an item with the same name already exists.
To save the file, either specify a different name, or move or delete the existing file and try again.

I am not sure where this collection is located in my Xcode project, since the navigator does not show anything, and the command line also does not skip any hints. I'm afraid to mess with the project.pbxproj file, as it can get a lot more confusing than just my image collection.

Edit: Dragging files back to the Finder from the trash was successful, but the Xcode browser no longer recognizes - or in this case still does not recognize - the .xcassets file. I am not sure whether to add anything to the .pbxproj file.

+67
ios xcode xcasset
Dec 07 '13 at 15:53
source share
9 answers

I just did it myself and figured out how to quickly solve the problem.

  • Go to the project folder in Finder . You should find that the Images.xcassets folder still exists.

  • Move it to a separate location, such as the desktop or something like that. It still has all the images and json files.

  • Return to Xcode and create a new asset catalog for the images.

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

    Name it Images .

  • Close Xcode and go back to Finder.

  • Copy the folders from the old Images.xcassets to the new Images.xcassets in your project.

  • Launch Xcode and you're back in business!

+181
Jan 18 '14 at 0:12
source share

If you did not delete it completely, you can simply drag it back from the Finder. (Right click on your project and select "Reveal in Finder" to check)

If it is completely gone, just go to Cmd + N → Resource and select "Object Directory". Then you re-add your images using drag and drop or right-click and "Add files to ..." and should be good to go.

Hope this helps.

+20
Dec 07 '13 at 15:56
source share

With the same problem today with Xcode Beta, I was also unable to create a new asset catalog for some reason. That was in the Watchkit extension project. Here's what I did to solve it:

  • In finder, I copied the existing images.xcassets from another folder in my application to my desktop.
  • Deleted the contents of this folder.
  • I copied the remote (single) image object from my garbage to a folder (on my desktop).
  • Drag and drop the entire folder to my project in Xcode.

This fixed it, and everything returned to normal.

+3
Jan 05 '15 at 18:49
source share

If you completely removed it, steps will also be taken to obtain new .xcassets images:

  • In the Navigator, click on the project.
  • Go to: File> New> File> Add Asset Directory> Name it.
  • To add AppIcon and LaunchImage to it:

Go to project setup:

  • General tab, Slide down to Application Icons and Launch Images
  • Click the "Next" button with "Application Icons" and select "Use Asset Directories"
  • A window will appear - select the name of the new Images.xcassets file and click "Transfer".
  • Select Also add LaunchImage. Now you can see the new .xcassets Pictures in your project :).
+2
Apr 24 '16 at 17:54 on
source share

I accidentally deleted the link to the resource folder so that it was no longer visible in Xcode. But when I checked with the crawler, the resource folder was still in the project folder.

If you have done this, simply open the file menu in Xcode (from your current project), and at the very top you can add (existing) files to this same project (back) - it says "Add files to ..."

+2
Sep 21 '16 at 12:36
source share

Right-click on something in your project and click on "Show in Finder". Search the project folder in the search device a bit and you will find it. I'm not on a Mac right now, or I would give you a more direct path directly to the default .xcassets .

In general, if you cannot copy / create a “new” folder in this place, because “an item with the same name already exists”, this means that you have not actually deleted this folder. You simply deleted the project links to this folder in Xcode. The folder on your hard drive is not going anywhere.

+1
Dec 07 '13 at 15:54
source share

[I understand this is a very old question from you @Aeveus] All answers speak of re-adding assets. Given that you cannot undo, one step missing from your original description is this:

In the project.pbxproj file there would be links to assets, as shown below:

 45AE4E781C183FBA0051674F /* Assets.xcassets in Resources */ = {... 

Assuming you have a source control system (git, etc.), you can either go back to the original contents of the project.pbxproj file or manually just re-add the deleted lines and re-open the project file in xcode, now you are all set up.

+1
May 31 '17 at 3:36 a.m.
source share

I had the same problem and I followed the steps above from Jason, but finally I got Image.xassets in red, so in order to find my images, I had to click Image.xassets and then in the upper right corner corner placed the absolute path in my image.xassets folder and fixed my problem. Hope this helps!

0
Feb 05 '16 at 18:42
source share

Usually the file link is removed from Xcode, the source folder still exists in the project directory.

Right-click the folder of your project, click "Add Files to" Your Project "", find Assets in your project and click Add, and you're done

enter image description here

0
Aug 28 '18 at 7:34
source share



All Articles