意外地从 Xcode 项目中删除了 xcassets 文件

我想从图像集合中删除一个文件夹,但是,我设法将整个 xcassets 文件扔进了垃圾桶。

普通的“ Put back”方法不可用,只需将删除的文件夹拖动到 Xcode 就会产生一个错误:

“ Images.xcassets”无法复制到“ ProjectPear”,因为同名项目已经存在。
要保存文件,请提供不同的名称,或者移到一边,或者 删除现有文件,然后重试。

我不确定这个集合在我的 Xcode 项目中的位置,因为导航器似乎没有显示任何东西,命令行也没有删除任何提示。我害怕搞乱 project.pbxproj文件,因为它可能会混乱得多,而不仅仅是我的图像收集。

编辑: 将文件从 Trash 拖回 Finder 是成功的,但是 Xcode 导航器不再识别——或者在这种情况下,仍然不能识别—— the。Xcassets 文件。我不确定是否要在。Pbxproj 文件。

68641 次浏览

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.

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.

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!

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.

I had same problem and I have followed the steps above from Jason, but finally i got Image.xassets in red color, so the in order to find my images I had to click in Image.xassets and then on the top right corner put the absolute path to my image.xassets folder and it fixed my problem. Hope it helps!

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 :).

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

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

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

I had the same problem. Open your XCode Project. Just go to File -> Add Files to...(your Project) -> Assets.xcassets and you are good to go!