如何将文件添加到 Xcode 9 中的项目?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45096410/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I add file to project in Xcode 9?
提问by aiur
I created a new project in xcode 9.
我在 xcode 9 中创建了一个新项目。
I want to add image file to project.
我想将图像文件添加到项目中。
When I delete this file from desktop,
当我从桌面删除这个文件时,
Image file appears in red?
图像文件显示为红色?
But in project folder, I find this image file.
但是在项目文件夹中,我找到了这个图像文件。
In Xcode 8 its working fine,
在 Xcode 8 中它工作正常,
Any idea?
任何的想法?
回答by enigma
It isan Xcode9-beta (9M136h)
bug. I don't know if it has been resolved in beta3
or not. Copy items if needed
copies the file to your project directory but still links to the original file.
这是一个Xcode9-beta (9M136h)
错误。不知道是不是已经解决了beta3
。Copy items if needed
将文件复制到您的项目目录,但仍链接到原始文件。
What I do is, after dragging the file to my project, I select the folder icon (see red circle in the image below) from File Inspector
and point to the copied file in the project directory.
我所做的是,将文件拖到我的项目后,我选择文件夹图标(见下图中的红色圆圈)File Inspector
并指向项目目录中复制的文件。
@pesch's approach works too. First copy the image to your project folder and thendrag it to Xcode.
@pesch 的方法也有效。首先将图像复制到您的项目文件夹,然后将其拖到 Xcode。
回答by pesch
Xcode 9 allows to have folders in Xcode synced with folder in your Finder structure. I assume this is a bug since Xcode 9 is still in beta and you are "ticking" the Copy items if needed.
Xcode 9 允许将 Xcode 中的文件夹与 Finder 结构中的文件夹同步。我认为这是一个错误,因为 Xcode 9 仍处于测试阶段,如果需要,您可以“勾选”复制项目。
Try moving the image to your project folder yourself and drag it from there to Xcode.
尝试自己将图像移动到您的项目文件夹并将其从那里拖到 Xcode。
This is what you would do to leave the Copy items if needed box unticked since you are doing it yourself.
这是您将在需要时复制项目框保持未选中状态,因为您是自己做的。
回答by Puneet Sharma
It looks like a XCode 9 bug. If you check the Full Path of your image file in Identity and Type Tab, it would show the location of the deleted file, hence the deleted(red) color.
它看起来像一个 XCode 9 错误。如果您在身份和类型选项卡中检查图像文件的完整路径,它将显示已删除文件的位置,因此显示为已删除(红色)颜色。
You can delete that reference and can use Add File To.. option to add the reference of (already) copied image from your source folder.
您可以删除该引用,并可以使用 Add File To.. 选项从源文件夹中添加(已经)复制的图像的引用。
回答by AntonTheDev
Although this is not resource related (images, etc). The issue that I'm currently facing with the Xcode 9.0 GM build is that adding the items to the project does not actually added them to my targets, although I selected them.
虽然这与资源无关(图像等)。我目前在 Xcode 9.0 GM 版本中面临的问题是,将项目添加到项目实际上并没有将它们添加到我的目标中,尽管我选择了它们。
Step 1 - Add Files to Project
步骤 1 - 将文件添加到项目
Add New Files and Select your targets
添加新文件并选择目标
Step 2 - View Files in File Inspector
步骤 2 - 在文件检查器中查看文件
You can clearly see in the file inspector that it is not added to those targets accordingly.
您可以在文件检查器中清楚地看到它没有相应地添加到这些目标中。
Step 3 - [Fix] Add New Added File to Targets
步骤 3 - [修复] 向目标添加新添加的文件
To Fix this, just check the targets that the files should be added to and you should be good :)
要解决这个问题,只需检查文件应该添加到的目标,你应该很好:)
回答by SteveCaine
I have seen this issue in Xcode 9.0 GM (build 9A235, same as the current release). It's intermittent; sometimes 'Copy items if needed' is honored, sometimes not.
我在 Xcode 9.0 GM(构建 9A235,与当前版本相同)中看到了这个问题。它是间歇性的;有时“需要时复制项目”会受到尊重,有时则不会。
In one case it seemed to be triggered by the presence of source control. I was working through an online tutorial where the provided project had no source control. Adding files here did honor the 'copy items' checkbox, but if I made the provided project a git repository first, adding files ignored the checkbox every time.
在一种情况下,它似乎是由源代码控制的存在触发的。我正在完成一个在线教程,其中提供的项目没有源代码控制。在此处添加文件确实遵循“复制项目”复选框,但是如果我首先将提供的项目设为 git 存储库,则每次添加文件都会忽略该复选框。