How to change the name of an Xcode file folder? - ios

(XCODE 5)
I may be wrong in calling it a file folder, but what I'm referring to is the folder that contains all the files that is created after making a new project. In my case, I saved my project onto the desktop, and originally named it something completely different. Now I want to change its name, but before when I changed the name of the folder it didn't work when I tried to build and run my app. The other question I had was how to move it to another location because same thing happened when I moved the project from the desktop.
I was also wondering what A or M or a ? mean beside the files on the left hand panel (inside the project)

In terms of renaming the folder, you're generally fine renaming the top level folder, but it can get messy when renaming one of its one of the subfolders. If you rename the subfolders, side affects include (a) messing up links in the Xcode project; and (b) if you're using version control, losing the connection between the previous change history and the new file. But if you're talking about the top level folder under which everything for the project is included, I've never had problems renaming that.
In terms of the A/M designation, a A means that new file has been added to the project; M means that an existing file has been modified. You'll only see these when your project is under version control (which is a checkbox you can check when creating your project.)

Related

Folder structure of xCode project is not appearing in git repository

I'm developing an iOS app with some other students of my class. One of them created our Xcode project and set up all the folders (groups) we need. These folders also appear in his finder. When pushing everything the folders are not visible in our repo. When I pull it, everything in Xcode is fine, all the folders are there (which also says the pbxproj-file). BUT in my finder none of these folders are there.
This is how it looks like
How can we also put the folders in Git, so that they are visible in our repo and the files are in them?
Edit: The below is the question I thought you were asking, but the image you added suggests a different problem. I would first make sure you're actually looking at the same directory. Cmd-rightclick the project in the navigation bar and make sure it's the folder you think it is. This is a surprisingly common mistake.
I would then make sure you haven't referenced external folders or put things in a strange place. Select a folder and open the right-hand sidebar (Cmd-Opt-1), and check the path. It is very common when you drag things into a project, or rearrange a project by dragging, to accidentally create absolute path references to locations outside your project.
Xcode has traditionally used groups rather than folders to organize files. Groups are a virtual structure, purely in Xcode. Most of the files are put into a single physical directory.
(Whether this is good or bad is a matter of taste. I've long preferred having most files in one directory to make reorganizing the structure easier, and to make it easier to write scripts that search or process all the source code. But over the years, and particularly moving to Git from Perforce and SVN, and especially with the rise of GitHub, I've grown to prefer the folders, and that seems to be the direction Apple is moving towards as well.)
In recent versions, Xcode has moved towards supporting folders directly.
You can see the difference in Xcode. This is a group without a folder:
This is a group with a folder:
Note the lower-left corner of the icon.
You can make folders from the local menu, either by right-clicking an existing folder/group, or by selecting files you would like to move into a folder and right-clicking:
I don't believe there's any shortcut to convert all existing groups into folders. You'll have to restructure. But as you create new things, make sure to create folders if you want those.
It's better to maintain relevant folder structure as mentioned by #Rob Napier so that when you modularise/move files in xcode the files are moved to the corresponding folder structure and they are in sync with the file system.
Right click on any one of the file(under view/vm) and -> click show in finder to check the absolute path of the file.

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.

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.

Moving files around in XCode and IOS 7

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.

.xcdatamodeld file not showing data model structure in Xcode

I have .xcdatamodeld file in my project but it not opening up into the data model.
When I click on the file in the left sidebar in Xcode, it continues to display the contents of the previously selected file instead of displaying the data model. Likewise, when I right click on the file and choose "Open As >", I cannot select to display it as a Data Model—nothing comes up. I checked out the code from the SVN repo and even the filer owner is not able to see it in his workspace.
This is a symptom that I have seen from time to time. In at least one case, this was due Xcode having the wrong path stored in the path component of the XCVersionGroup section of the project.pbxproj file, and having an apparently unnecessary additional name component in that section. It would probably be possible to manually edit this file, but I'm always reluctant to monkey around with the project file directly, and fortunately there's an easier way.
Navigate to your .xcdatamodeld file in the Finder. The easiest way to do this is Right click/Ctrl-click on the .xcdatamodeld file and select "Show in Finder".
Drag the file from the Finder and drop it immediately above or below the current reference to the .xcdatamodeld in the Project Navigator in your Xcode project.
Click OK to accept the import, ensuring that you are adding it to the correct targets. (Which targets are correct will depend on your project.)
You will now have two references to the same file in your Project Navigator. Clicking on either of them will now bring up the desired data model structure.
Remove the duplicate reference to the model file. Click on one of the file references (doesn't appear to matter which, though it may be better to remove the old one) and press Delete.
In the resulting confirmation dialog, be sure to select "Remove Reference" only, and do NOT move the file to the trash. (The two references point to only one actual file in the file system. Moving to trash would thus trash the only copy.)
You're now left with just one reference to the data model, and it works.
One thing that appears to trigger this bug is moving the .xcdatamodeld file in the file structure on disk. Even after correctly re-associating the file with the new location (i.e., it no longer appears in red in the sidebar), the one section of the Project file mentioned above is not correctly updated, and thus the file is not treated fully correctly as an Xcode Data Model file.
I encountered the same issue in Xcode 6.3
The only solution that worked for me was to move the .xcdatamodeld file out of my 'Resources' folder and into the project root folder in the Xcode project explorer (location on the filesystem doesn't matter)
I'm still not sure why, just moving the location of the file in the project structure causes it to not show up at all when clicked.. but apparently, at least in my setup, it doesn't like living in the Resources folder..
For some dark reasons, sometimes Xcode needs the xcdatamodeld fiel to be in the root folder.
I wrote an answer here that explain how to do this, but also a workaround to have this file where ever you would like to.
Cheers!
The .xcdatamodeld file is a package. It contains .xcdatamodel packages, one for each version of the model. Inside every .xcdatamodel there is a contents file, which is an XML with entities description. To see what is inside your packages, right-click them in Finder and choose Show Package Contents option.
Perhaps you didn't add the contents file into your repository. This way you will not be able to see your model when you create a brand new working copy from it.
I was victim of this problem today on Xcode8.
I solved it simply by placing the xcdatamodeld file outside any group in the Project navigator (left pane). As soon as I move it into a group, I can't open the little guy anymore.
I had a similar problem with Xcode 7.3.1.
It turned out to be related to the way the data model packages were configured.
I discovered that there was one embedded model package nested inside another. Let's say a top level data model called FolderNodes.xcdatamodeld containing another with exactly the same name ... FolderNodes.xcdatamodeld. Inside FolderNodes.xcdatamodeld is the actual contents file that has the model info.
The solution for me was to drag the embedded package FolderNodes.xcdatamodeld ( number 2) into the Xcode project and NOT its enclosing folder.
Apple uses the package for versioning but I think the logic associated with moving the data model file somehow breaks the original package creating a redundant wrapper.
Make sure your Version Editor is not active.
Having the Version Editor open results in the xml code to be displayed instead of the Data Model. You will also not be able to choose Data Model in the context menu of the xcdatamodeld file within the Project Navigator.
Happens on XCode 8.3 as well.
For me, moving the physical file to a different folder, then deleting the original reference, then adding it back to same place and establishing the reference again does the job.

Resources