Accidentally removed xcassets file from XCode proj

2019-01-13 17:03发布

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.

9条回答
forever°为你锁心
2楼-- · 2019-01-13 17:31

If you have deleted it completely, then also these are the steps to get a new Images.xcassets:

  1. In the Navigator, click on the project.
  2. Go to : File>New>File> Add Asset Catalog> Name it.
  3. To add AppIcon and LaunchImage in it:

Go to the Project Setting:

  1. In General Tab, Slide down to App Icons and Launch Images
  2. Click option next to App Icons Source and select Use Asset Catalogs
  3. A window will pop up- select the name of your new Images.xcassets file and click on Migrate.
  4. Select Also add LaunchImage. Now you can see the new Images.xcassets in your project :).
查看更多
疯言疯语
3楼-- · 2019-01-13 17:38

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..."

查看更多
爷、活的狠高调
4楼-- · 2019-01-13 17:38

Right click on anything in your project and click "Show in Finder". Search around in your project folder in the finder for a bit and you'll find it. I'm not on a Mac right now, or I'd give you a more direct path straight to the default .xcassets folder location.

And anyway, if you're not able to copy/create a "new" folder in that location because "an item with the same name already exists", then that means you didn't actually delete the folder. You just deleted your project's references to that folder in XCode. The folder on your hard drive didn't go anywhere.

查看更多
干净又极端
5楼-- · 2019-01-13 17:43

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!

查看更多
欢心
6楼-- · 2019-01-13 17:44

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

查看更多
forever°为你锁心
7楼-- · 2019-01-13 17:45

[I realize this is a very old question from you @Aeveus] All the answers talk about re-doing the adding assets again. Given you could not undo, the one step that is missing in your original description is this:

In your project.pbxproj file, there would have been references to assets as below:

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

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

查看更多
登录 后发表回答