13

I created a new project in xcode 9.

I want to add image file to project.

enter image description here

enter image description here

When I delete this file from desktop,

Image file appears in red?

enter image description here

But in project folder, I find this image file.

enter image description here

In Xcode 8 its working fine,

Any idea?

aiur
  • 649
  • 2
  • 7
  • 21

5 Answers5

5

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.

image of the file inspector showing folder icon

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

enigma
  • 865
  • 9
  • 22
3

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.

pesch
  • 1,976
  • 2
  • 17
  • 29
  • Have you found an option anywhere in Xcode 9 to unsync the project navigator and finder directory? – ocwang Sep 11 '17 at 09:17
2

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.

Puneet Sharma
  • 9,369
  • 1
  • 27
  • 33
  • I does not work either. I'm using Beta 3 and I first copy all the files (not images, but swift files) to my project's directory tree. I tried both dragging from Finder and by using Add File To. It does the same buggy stuff: moves the file to the project dir and paints it in red on the project tree. When I move back the files manually, they are painted in black again in XCode, but the compiler does not see some classes declared in those files. This is the worst bug I've seen in XCode. And no, I will not report it to Apple. It's time consuming and useless. – nbloqs Jul 23 '17 at 15:22
2

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

enter image description here

Step 2 - View Files in File Inspector

You can clearly see in the file inspector that it is not added to those targets accordingly.

enter image description here

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

enter image description here

AntonTheDev
  • 899
  • 6
  • 13
1

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.

SteveCaine
  • 512
  • 4
  • 13