I created a new project in 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,
Any idea?
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.
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 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.
Related
I have facing this issue when I was changing project name and copying my project from one mac to another. There are some red texts indicate the missing files from the project source codes(But I have all files in Project folder) I have used cocoapods in this project. How to avoid these?
Here I have shown my project screen shot.
As per your description... you must be having some issue in your project.pbxproj file. Please check that file. Common issue happens in that file when you try to merge different branches having conflicts in project structure.
There could be different reasons of this:
It may happen because the xcode is open and the source folder is not available.
It may happen when source path is not found in your system and xcode shows that.
For resolving this, quiet xcode and reopen your source from .xcodeproj again, will resolve the problem.
Click on the file, then on the far top right of Xcode look under Identity and Type Check and see if the path to the file is correct. In my case is was not so I had to click on the small folder icon (not the arrow icon) and select the folder in finder.
In new Xcode 9 I want to add images in project. But If I add images and try to use it in code or in storyboard my images not showing in simulator. But in Xcode 8 all works fine. How to fix it?
Note : This Problem does not Exist Anymore in newer XCode
If you have dragged image in your project, you must select Copy If Needed While adding any file into your project.
After Adding Image take a look at your image if it is available to target, I have face similar issue with other file types too.
In xcode9 it was not selected by default even after selecting copy if needed.
Yes - this is super annoying. With XCode 9, now in addition to dragging a new image into the XCode Project Navigator (the left-hand list of files), you now have to go into Targets for your project, go to "Build Phases" and manually add the image file to "Copy Bundle Resources" using the "+" button at the bottom of the list of files.
This is required for any object you used to have to just drag into the project, including third-party frameworks and bundles.
PS: in dragging the image into your project you don't have to have "Copy Item if needed" selected if the image file is already somewhere in your project folder or a subfolder thereof.
If you have to handle multiple images, it is probably more convenient to copy the resources to your target app in the General Settings > Build Phases > Copy Bundle Resources
Copy Bundle Resources
This does the same as checking Target Membership for the resource – but you can add multiple images to your target app at once.
Check release notes of XCode 9.1:
Adding files to a project now adds them to the selected targets. (34551617)
https://developer.apple.com/library/content/releasenotes/DeveloperTools/RN-Xcode/Chapters/Introduction.html
Xcode keeps prompting telling me I don't have a certain image in the project and it errors when I try to build. If I deleted the .png Xcode is complaining about from the project, why does Xcode error out when I try to build?
[Edited by Rhubarb (got too big for the comments)]
I'm getting the same thing with these details. The copy command looks like this
CpResource MyIcons/../13-bicycle.png /Users/Me/Library/Developer/Xcode/DerivedData/MyProject-cxsohyxdecdbptgrrtaixbhhixrj/Build/Products/Debug-iphonesimulator/MyProject.app/13-bicycle.png
then there's a bunch of setenv and the command is translated to "builtin-copy" but none of that matters, the result is when I compile I get this error:
error: /Users/Me/Development/MyProject/MyIcons/../13-bicycle.png: No such file or directory
Now, I opened the Copy Bundle Resources tab as suggested by Robert Harvey, and my .png is there, with nothing appearing in read. And it is in the file system (Finder) and in the Project Navigator. So I deleted it from the resources using the - button and added it manually using the + button at the bottom left of the list in the Copy Bundle Resources tab. This put it at the root of the project in the Navigator, so I moved it into my group again - but no luck, same error. So I just deleted it altogether (from the Project Navigator, allowing it to be moved to Trash). That worked, but I ran into the same error with the very next icon (it only reports one or two at a time).
Looking at the error message, it appears to think that MyIcons is a folder. It's not, it's just a group. There is no such folder, I can see in the file system.
When I added via drag-drop, I left the "Copy items into ... group folder (if needed)" checked and the "Create groups for any added folders" button selected. But note that I only dragged icons (en masse) into an existing group; I did not drag over any folders, nor where any groups or folders created. But somehow, the compiler thinks that these resources are in a folder in the file system that doesn't exist.
I right clicked the icon in the Copy Resources List and tried both Show in Finder and Reveal in Project Navigator: and both worked - the file is there and it knows where to get it - until it builds.
I haven't even found a workaround beyond deleting the icons yet - cleaning doesn't work. I think my group is corrupted.
look up here XCode Build – CopyPNGFile Error and No Such File or Directory .
I had same problem and this solution helps me.
If you receive either of these annoying errors when building your
xcode app, something has corrupted in your project bundle.
Open your project in Xcode
Click on your project
Click on your project under Targets
Hit the build phases tab
Open “Copy Bundle Resources” near the bottom
Look for any resources listed in red!
I had the same problem but my solution was a bit different:
Open project in Xcode
Open project navigator
In the filter down below, search for your erroneous file name
I found the file under a group called "Recovered References" and it was marked in red
Delete the red files and everything should work perfectly
Okay here's the unsatisfactory workaround that fixed it for me.
(First, note that when I right-clicked my dodgy Group in the Project Navigator) it looked like any other group except that Open in External Editor was greyed - weird eh?)
I closed XCode and restarted it.
=> Now I see all of the icons under the offending group are red (in the Project Navigator)
Delete the entire group.
Create a new group (same name) and drag-drop the icons from the original source into the group
=> Error failed to copy (or some such - I can't remember but I have seen and fixed this before - and seen it elsewhere on SO)
This error is due to leftover icons, so to fix this one now,
I deleted all other groups with icons and moved their icons to trash
open finder at the project location
delete every icon in the project (sort by kind, delete all the .png)
make a new group again, and drag all the icons in _again.
whew, now hit Builder
=> XCode crashes.
Lovely.
Restart Xcode
fingers crossed: Build
=> it works. Brief celebration and back to work.
(See what I mean about unsatisfactory)
perhaps you move the file named **-Prefix.pch,you can change the dictionary of the file ,do like this : the error about “no such file or directory”
Check your project file paths. If there is a space in any of the folders, it causes this error. Simply remove spaces.
Using XCode 10, I got this error after deleting some files I no longer needed in my project.
In my case, I went to XCode, clicked on the project name, then under Resources, the missing files were listed in red. All I did was to delete them.
In case you need the files, you will need to add them by going to File ->Add files to , then select the files. After selecting the file, make sure you have Copy files if needed checked.
Hope that helps someone.
HappyCoding
try set target CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS=NO
XCode Build – CopyPNGFile Error and No Such File or Directory
If you receive either of these annoying errors when building your xcode app, something has corrupted in your project bundle.
Open your project in Xcode
Click on your project
Click on your project under Targets
Hit the build phases tab
Open “Copy Bundle Resources” near the bottom
Look for any resources listed in red!
When I created my project, I called it "Project1". Then, later I've changed it to "Project2" from the Xcode. I changed all "Project1" to "Project2", but now, when I compile my project, it looks for files in Project2/Project1/myFile.swift and I get the next error:
<unknown>:0: error: no such file or directory: '/Users/myusername/Copy/Projects/Project2/Project1/myFile.swift'
I need to make that it will look at
/Users/myusername/Copy/Projects/Project2/myFile.swift
without Project1 in the path.
How can I solve this problem? Also, I changed from Xcode Identity and Type section Location of my project.
Today I had the same problem when I renamed the folder containing the Xcode project and some parent folders of it.
In my case there where a .swift file shown with it's name in red in the list of files of Xcode (Navigator area). I think that this means that Xcode was not capable to find that file.
I selected that file (actually it's not a real file but a representation of it).
Then, in the File Inspector (Utility area), I clicked on the Folder icon and chose the file on Finder.
This worked for me.
Renaming projects in xcode in one of the most annoying things in iOS development. I assume you want to rename your app. I faced this problem once and figured out a simple, clean way to do it.
Go back to the point where everything worked.
Open project in xcode and click on the project icon in the project structure( first file)
Go to the info tab
Search for Bundle Name. Most probably it will automatically be set to $(PRODUCT_NAME) which is a shell variable that will set your app name the same as the project name.
Set it to whatever you want your app name to be
Done
Note : If you use custom URL Schemes this might produce an error when redirecting.
ALWAYS use git or some other SVN in your projects. This will come in handy in this kind of situations
Change you folder name in you finder "Project1" to "Project2"
Remove "myFile.swift" file from project (copy on Desktop)
Restart Xcode. Copy "myFile.swift" in project select "Copy file to folder" hope this will help.
When I move iphone project directory to a new path.
There are some red texts indicate the missing files from the project source codes.
How to avoid these?
Here is how to locate the missing (red) files using the Xcode 4 interface:
Select the file or files in the left hand Project Navigator (the folder icon)
In the right sidebar click on "File Inspector" which is the leftmost icon resembling a page
In the "Identity and Type" section, there is a grey box labeled "Location".
Click on the small icon to the lower left that resembles a file browser - this will come up with a file browser to locate the file.
Voila, you are done.
Xcode 7
1.) Right click on the red (missing) file.
2.) Select "Show File Inspector"
3.) Look at the right hand side of the screen under "Identity and Type" between "Location" and "Full Path"
4.) Click on the folder icon to the right of the file name.
5.) Navigate to the file's new location in the pop-up window and select the file.
I encountered this issue when copying my project from one mac to another.
The solution for me:
assuming your files are grouped (in folder)
from xcode open the group in file inspector
The group will probably be missing the absolute path.
press the little icon nearby to pick the folder to associate the group with.
restart xcode to see the changes.
I had the same problem, when I changed the permission on the files/folders to everyone read/write they then appeared in Xcode.
This worked on a Pod project. Quit XCode.
rm -rf project.xcworkspace/xcuserdata/*
Restart XCode and reopen project.
In Finder, create a duplicate of the project directory just in case all goes squiffy.
In Finder, open the project directory that contains all the files with red references
For all the red files you see in XCode, except the info.plist file (see step 5 below), highlight them in Finder and drag them from Finder to XCode's project navigator. i.e. import them.
In XCode's "Choose options for adding these files" window: a) Select Copy items into Destination's group folder (if needed)
b) Select Create groups for any added folder
c) Select Add to Targets, and press Finish
Highlight and drag the info.plist file from Finder to Project Navigator and repeat step 4 WITHOUT selecting Add to Targets
If you had groups in Project Navigator (e.g. Supporting Files), reorder the files to be in the right places.
Delete the original bad red references in Project Navigator, and Cmd-Shift-K to clean for good measure.
Build and run on a device to remove the bad reference to the .app file
you just have to locate the missing file press in file icon in the identity and type you will find the full path just locate your file where do you move it click the file icon
When you create these files be sure to save in your app directory. Or if you import classes from other project be sure to check the copy option.
I dont know if this is the main reason but when you are importing files to the application, do you mary the "Copy items in to destination group's folder (if needed)" ?
this make sure the file is not only referenced but added to your project folder and ir will move any where you move your project.
Did you move files in to folders directly in your project folder and not in xcode?
This worked on a Pod project.
go into finder and project.
right click on your project .xcworkspace and click show package contents
right click on contents.xcworkspacedata and open with textEdit then make sure file path is correct. If project has been moved this can change
I also did this below but now sure if you need it
Quit XCode.
rm -rf project.xcworkspace/xcuserdata/*
Restart XCode and reopen project.
If you create an Xcode project, then move the .xcodeproj file or the newly created project folder to a different folder using Finder, subsequent builds may show many missing files which still reference the original folder locations (which no longer exist because you moved them). These missing files can appear as red text or as issues in the Issue Navigator.
This can happen when Xcode is configured to automatically add or remove files to/from source control (under Xcode > Preferences > Source Control). When configured this way, simply creating a project in Xcode causes new project folders and files to be marked for addition to source control. When you later move the project folder or .xcodeproj file these pending adds now point to missing files.
To resolve this issue when Subversion is the source control program, revert the pending adds for the phantom items from your local working copy folder. In my case this requires dropping into a Terminal window, navigating to the parent of the phantom project folder, then reverting the automatic add, e.g.
cd /my-working-copy-folder
svn status --depth infinity
svn status --depth infinity existing-parent-folder/phantom-project-folder/
svn revert --depth infinity existing-parent-folder/phantom-project-folder/
Note that the first svn status command will list both missing files as well as properly added, modified or deleted files which you must take care to avoid reverting. The second status command is "practice" for the final revert command, to ensure you've specified the proper path to revert.
I do not know git but I assume it offers corresponding commands.
It's too simple to do :
Close the project that includes the missed files and open the Xcode, go to "Organizer">"Projects" and remove the project from the list there. Open your project from Finder and that's it.
hope this help.