Moving files around in XCode and IOS 7 - ios

I move some files into a subdirectory but now I get linking errors saying files can't be found. Where do I go (like a projects file) to tell XCODE where to look for the new files?
I tried removing everything and adding them back in but I still get missing files even though they are one directory in and added to the project.

Select a file in left panel, open inspector panel on the right and choose a path to file there.
Note: it's more efficient to do that if your files are organized into folders; that way, you only need to change the path to folder and the elements are relative to it.

Related

Xcode 9 - Some folders marked with red text

In my project, there are some folders that have red text.
The project compiles and everything works, but I can't understand why only some folders have red text.
Check this.
It means they are not found on disk where your project believes they should be. Control-click and Show In Finder to see the folder location to locate the file and drag it back in to the project, and delete the bad reference.Missing. Maybe you moved them somewhere without deleting them from the project or something.
Edit: Don't delete it before add it first, and you should save backup from the files in another folder, also you have to use source controls like Bitbucket, GitHub, or GitLab.
The UI error feedback notifies you that the path is not found. You can select a new one using the folder icon in the right panel. In this way, all files in the folder keep the configuration so it is more convenient.
I illustrate it in the above screenshot.

Duplicate Xcode project uses old project_dir

I am trying to create a duplicate of my Xcode workspace. I have made a duplicate folder in Finder. Let's call the original Project_v1 and the duplicate Project_v2.
When I open Xcode in order to deal with all the additional issues i notice that my location/fullpath are both /Users/abcd/Desktop/Abcd/Project_v1/Project.xcodeproj (Relative to Group) even though I opened Project_v2 folder.
When I watch online tutorials about this the path is always the new path. If I choose Project_v2 by clicking the little folder icon under Identity and Type then my entire structure in left pane changes (folders go blue not yellow, project app icon turns to a folder etc).
How is it even possible that my project contained within Project_v2 is referencing v1? And how do I safely change it to v2 whilst keeping everything else correct?
Ok so basically I just have to keep ditching copies and starting again using a different name until somehow things kick in.
For some reason when I try to change the path of the project in the File Inspector it randomly either allows me to select the xcodeproj file or not. If it does I am ok. If it doesn't there's nothing I can do but start again.
The key is being able to change this path but seems random whether allowed to do so.
EDIT:
Seems the only way to be able to sort this out is to change the projects path to Absolute, choose the folder Project_v2 (not the xcodeproj file as this isn't possible), then change back to Relative to Group and then actually choose the xcodeproj file as the intended location.

Error: no such file or directory

My project was working perfectly fine. I then moved some files around from the project's root directory to some subfolders. Now, when I try to run the app, I receive this error message:
<unknown>:0: error: no such file or directory:
'/Users/anapaix/Desktop/currencyExchange/CommentsController.swift'
And I receive this same error for all 20 of the files that I moved around.
Additionally, the files now show up in red like this in my project:
When I double click the file, an empty Swift file shows up, like there is nothing inside. I have a feeling there should be some easy fix to this, in order for Xcode to recognize these files, but just have no idea what it would be.
You moved the files. Xcode doesn't know that. You need to tell Xcode where the files are. (Note: the other answers work too, but if you don't want to remove them and add them again, you can use this method)
Select your red file(s), open the File Inspector (Option+Command+1), and click the folder (circled in red in the below screenshot). Then find your file(s) and click Choose. The filenames should go back to being black.
If multiple red files are in the same folder, you can select multiple files in the Project Navigator (left column, Command+1), click the folder icon in the File Inspector (still the one circled in red, but the text will be different; it might say "multiple selected" or something) and click the folder containing the files. Xcode should automatically detect all of them, provided the filenames haven't changed.
Go Xcode->File->Add Files... and add missing files to the project.
when you move any file in finder from the projewct workspace then xcode doesn't recognize the new path automatically, and xcode consider it as deleted. So,Please remove this files that are in red colour in your explorer.
Then again drag the files from the finder in to your project.
This way your project found the new file path of files for the compling.

Files in Xcode not working (names in red)

I renamed my app folder to try and change the name of the app because it didn't work in the project navigator and when I did so, all files came up in red. I have tried to fix it by renaming the files back to how they were but it still doesn't work.
Any help would be greatly appreciated.
Link to dropbox: https://www.dropbox.com/s/omvo0saff0z9ncc/TicketekApp%202.zip?dl=0
If files marked in red, they are "not found" by Xcode.
You either moved or deleted them within File Finder, outside Xcode.
Delete the red marked files within XCode, then add them again to XCode.
This will solve your problem.
I solved this problem as follows:
click on the Group name in which file names are showing in red colour in the Xcode navigation area (Navigator) on the left side. In the Utility area on the right side in Xcode open up File Inspector tab. There is a Field named Full Path:, click on the arrow placed last to the path. You will have popup window showing your project path. Change The Group Folder in which you already moved your files from Finder.
In my case after moving the projects to a new folder and fixing each file location, the project compiles properly but the files names were still in red.
The problem was that the files were grouped in groups. The group was the cause of the red names of the files. So I added new groups, with identical names to the old ones (Xcode allows to do it since it does not know were is the old group), moved the files from each group to it's new group and deleted the old groups.
Now all the red names are gone.
For me, I had to make a new folder again and add everything back
Another reason for this problem might be your project.pbxproj file. In my case, after doing a git merge, one of the PBXGroups missed a line of code. After comparing it to the others and adding the missing line, problem disappeared.
In my case I had a contents.xcworkspacedata file that had the below, an absolute pathname to a couple of files (just 2 out of about 40). When I checked the project out on a different machine, it showed these files as "red" (makes sense, the newly checked out project is in a different location). I don't even know how a couple of files ended up in here. It just doesn't make any sense to use absolute paths at all.
To fix, I just modified this file to remove those lines, moved the files away into a tmp dir (since they were there), and added the missing files in Xcode.
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "group:/Users/jack/projects/myapp/myapp/MyController.swift">
</FileRef>
<FileRef
location = "group:/Users/jack/projects/myapp/myapp/CustomView.swift">
</FileRef>
...

Some files are located outside of "MyApp" directory in my iOS app - why?

I'm now developing my first iOS app, and I found that two of my classes (hence, four files) are located outside of my MyApp/.
So in my filesystem, here's the current situation:
My App
- ClassA.h
- ClassA.m
- ClassB.h
- ClassB.m
MyApp/
MyApp.xcodeproj/
MyAppTests/
Other than the two classes, all of my class files are located in MyApp subdirectory. The other resources, such as Core Data model file or images are saved in the same directory.
However, why are the two classes, and only the two classes, located in the outside of MyApp subdirectory? When I move those files to the supposedly correct location, those files are no more "valid" in Xcode with the color of the file name is converted to red.
So here's my question:
Why are those two files located there?
Do they have any issues if they remain to be located there?
Should I fix this issue and save it correctly? I think I haven't had any issues so far with the Simulator and the actual iPhone...
I use iOS 7 and Xcode 5.
•Why are those two files located there?
A: When you have created these files or imported from external directory, you may have not taken care of the group/folder these files are getting created/imported into. Hence they are inside the main app folder in the file system.
•Do they have any issues if they remain to be located there?
A: No, this is certainly not an issue in the correct functioning of your app, but it is always good to manage your files under groups/folders for better file structure and it is easier to find files when they become large in number.
•Should I fix this issue and save it correctly? I think I haven't had any issues so far with the Simulator and the actual iPhone...
A : This depends on you. If you like to keep your files in folders and like everythin arranged in some pattern, then yes you can divide the app into different folders. When you move the files in a folder, the reference of those in XCODE should change as well, and thats why you see those files in red in XCode. No worries. Just delete the files and add them again. Make sure you uncheck the option "Copy files under detsination group's folder".
Now, you may seem the option of creating New Groups inside XCode. But it is good to be aware that these groups do not create separate folders inside file system. These are just for Xcode refernce. So, a neat way is to create folders outside of XCode, and then import these folders(can be empty) in Xcode. Now when you add any file in these imported folders, even from XCode, it will go inside the correct folder in file system.
I am sorry I am not on my MAC right now, so cannot paste actual images, showing how to do it. Feel free to comment, if I have instead of solving the issue, have rather confused you more:D
You can put your source files wherever you want, as long as Xcode knows where to find them. You can leave them here, or organize it in another way, as you seem to be willing to do.
So, if you want to move these files in your Myapp/ subfolder, just move them there, and when Xcode complains it can't find them, highlight all those files in red in the navigator, and in the "File inspector" pane (right hand side of the window), click on the little Folder icon to browse to the new location. If you selected all files you don't need to do that 4 times, Xcode will find it out by itself.

Resources