Accidentally removed xcassets file from Xcode project

66,265

Solution 1

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!

Solution 2

If you didn't delete it completely, you can just drag it back in from Finder. (Right click your project and select 'Reveal in Finder' to check)

If it's gone completely you simply go Cmd+N -> Resource and select Asset Catalog. You then re-add your imagages via drag and drop or right-click and 'Add Files to ...' and should be good to go.

Hope that helps.

Solution 3

Usually the file's reference is removed from Xcode, the original folder still exists in the project directory.

Right-click on your project folder, click "Add files to "your project"", find Assets in your project and click Add and you're done

enter image description here

Solution 4

Had the same problem today with Xcode Beta, I also couldn't create a new assets catalog for some reason. This was on a Watchkit Extension Project Here's what I did to solve it:

  1. In finder I copied an existing images.xcassets from another folder in my app to my desktop.
  2. Removed the content of this folder.
  3. Copied a deleted (single) Image Asset from my trash into the folder (on my desktop).
  4. Dragged the entire folder into my project in XCode.

That fixed it and everything went back to normal.

Solution 5

I accidentally deleted the reference to the asset folder so that it was no longer visible in Xcode. But when I checked from the finder, the asset folder was still in the project folder.

If you did that, just open the file menu in Xcode (from within your current project) and at the very top you can add (existing) files to that very project (back again) - it says "Add files to..."

Share:
66,265
Aeveus
Author by

Aeveus

I solve problems.

Updated on July 08, 2022

Comments

  • Aeveus
    Aeveus almost 2 years

    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.

  • Aeveus
    Aeveus over 10 years
    Ah thanks, I found the folder, however it appears to be missing the majority of its files. Would you happen to know whether the rest is retrievable?
  • nhgrif
    nhgrif over 10 years
    I'm not sure. If it's something that was in your project but now isn't, then it's either somewhere in your project folder in Finder, or it may have been moved to the trash bin.
  • Aeveus
    Aeveus over 10 years
    Thanks, I've managed to drag everything back into the folder, but the navigator doesn't show the file. Is there a way to refresh the navigator (or something similar)?
  • Finn Gaida
    Finn Gaida over 10 years
    Well, Cmd+W and reopening has ever helped, but is worth a try. If you found the files in Finder though, just drag 'em back in and that should be it
  • Aeveus
    Aeveus over 10 years
    Well dragging the files back in went fine, it's just that the navigator doesn't recognise the .xcassets file anymore, as it's simply not visible. I can find it just fine in Finder, but the XCode navigator doesn't believe me.
  • Finn Gaida
    Finn Gaida over 10 years
    This might sound dumb, but for me restarting XCode and cleaning the project had done the job scaringly often
  • Aeveus
    Aeveus over 10 years
    At this moment, I'm a bit frustrated, so I welcome all answers. I've already tried rebuilding and cleaning the project in addition to restarting XCode; didn't help. :(
  • Finn Gaida
    Finn Gaida over 10 years
    According to this (stackoverflow.com/questions/12454430/…) answer touching the directory might help. I really can't think of any other possibility other than deleting the xcasset and re-adding all images to a new one...
  • Aeveus
    Aeveus over 10 years
    Thanks for the suggestion, I've ran touch on the root project directory, the directory containing the .xcassets directory, the .xcassets directory itself, and the .xcodeproj directory, to no avail. I might just have to steel my resolve and start manually re-adding all images...
  • Jesus Rodriguez
    Jesus Rodriguez about 8 years
    Wow, I just deleted in my Assets.xcassets by accident and it still works, but this doesn't work so I can not add new images... I looked for the folder everywhere without success
  • Sean Blaney
    Sean Blaney about 8 years
    @JesusAdolfoRodriguez, If you selected 'Move to Trash' when you accidentally deleted the asset catalog, you should be able to find the folder in the trash, unless of course you have already emptied the trash.
  • djdance
    djdance about 6 years
    or just drag-n-drop from Finder
  • Merricat
    Merricat about 5 years
    Nice, worked for me. FYI for anyone who accidentally deleted this, I think it's because we tried to Cmd+Delete a file while inside the Assets folder. Instead, just press Delete to delete a file