Duplicate Xcode project uses old project_dir - ios

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.

Related

how to change path of iOS file to show project path

To manually include a number of “library” files into my project, I open my project in xCode. And then I open the “library” folder in finder. Then I drag and dropped from the folder into my project. But now when I go to Buid Phases > Compile Sources I see the path of the files I just copied to be …/download/… instead of /project/.... This is bad because when I push to git, the files aren’t passed along and they look red on the computer of anyone else who sync, for the obvious reason that the path specified does not exist on their machines. How do I fix this? As in, when I drag and drop I was expecting for the files to be copied and not just referenced. But they weren’t. Is there a simple fix? Note: I mark “copy items into destination group’s folder (if needed)”.
Also when I open my project in finder, the group that is supposed to have the "library" files isn't in there.
This is a tricky one. But I can assure you it is human error (well, I think anyway). Do this:
Right click on the group and select "show in finder". You will see that the group belongs somewhere else. So as long as you keep adding to the group, it won't really ever show up in your project. To fix, delete the whole group, type the group by hand, and then try drag and drop again.

How to change the name of an Xcode file folder?

(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.)

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.

Loading a different plist depending on the target

I thought it would be interesting to attempt building multiple apps using the same code base, where the only differentiating data is held in a few plists. For example, one plist holds some theme info - a few key/values to drive the color scheme used in the app. I'll call the original version of this theme.plist.
I soon learned that I should create multiple targets in my project, and have been able to add these successfully. Each one, via it's own appname-info.plist, has a different name and bundle id - it's neat seeing all three on my home screen without any real extra work.
But right now they are all identical. I haven't figured out how to use a different set of data for each one.
My first thought was to have some folder for each target - each with its own theme plist named theme.plist - and somehow distribute each target with a different folder. But researching that idea doesn't get me much google juice.
So what about multiple theme files? Ok, so far that looks better - I can create an app1-theme.plist and 'app2-theme.plist' with different values for the same keys in each. And Xcode even lets me use some flags to say which targets should include each resource.
But I don't know how to load the appropriate plist at runtime. I need to examine something (the bundle ID?) and then assign the appropriate name of the theme plist to something (what)?
It seems like this might have something to with #ifdef, whatever that might be...?
Can someone explain how I should be looking to accomplish this? Am I on the right track? I'm happy to put some reading time in but I don't even know what to look up yet.
You are just about there. Xcode supports having multiple files with the same name in a project, one way you can do this by storing them in different folders within your project folder.
Unfortunately at this point Xcode won't give you a lot of help, so open your project in the Finder, create one subfolder for each of your apps, in those folders place a copy of the plist. Now add each copy in turn to your project, making sure you add each to just one of your targets.
You might want to create a group in Xcode called, say, "Theme files", to keep them altogether.
HTH
What you are trying to do is trivial. If you select a file from your project, and bring up the "File Inspector" in the utilities area (Press Command option 1) you should see a section "Target membership". Each target in your project will be listed, with a checkbox next to it. If you check the checkbox for a file and target, that file is built into that target. Un-check the checkbox for a file and target and that file is not copied over to the specified target (you may need to run a clean, and delete the app from the target device, to get rid of files that used to be included but that you have un-checked. Xcode generally won't automatically remove things that used to be included.
You could create a directory in your bundle and teach your app to scan that directory for plist files. Then include a different set of files in that directory for each target and each target app's behavior will change.

.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