How can I add file to project in Xcode 9?

末鹿安然 提交于 2019-11-29 03:56:38

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.

Try moving the image to your project folder yourself and drag it from there to Xcode.

This is what you would do to leave the Copy items if needed box unticked since you are doing it yourself.

It is an 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.

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.

@pesch's approach works too. First copy the image to your project folder and then drag it to Xcode.

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.

You can delete that reference and can use Add File To.. option to add the reference of (already) copied image from your source folder.

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.

Step 1 - Add Files to Project

Add New Files and Select your targets

Step 2 - View Files in File Inspector

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

To Fix this, just check the targets that the files should be added to and you should be good :)

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!