How do you keep Xcode project source files in sync with your file system directories?
Asked Answered
M

3

21

I'm new to XCode and I find the file management a huge pain. In most IDEs, you can simply have the project source tree reference a directory structure on disk. This makes it easy to add new files to your project - you simply put them on disk, and they will get compiled automatically.

With XCode, it appears I have to both create the file and separately add it to the project (or be forced to manipulate the filesystem through the UI). But this means that sharing the .xcodeproj through source control is fraught with problems - often, we'll get merge conflicts on the xcodeproj file - and when we don't, we often get linker errors, because during the merge some of the files that were listed in the project get excised. So I have to go and re-add them to the project file until I can get it to compile, and then re-check in the project file.

I'm sure I must be missing something here. I tried using 'reference folders' but the code in them doesn't seem to get compiled. It seems insane to build an IDE that forces everyone to modify a single shared file whenever adding or removing files to a project.

Mychael answered 20/2, 2010 at 21:25 Comment(1)
This is probably not what you want to hear, but this is the state of things. I'm surprised that you're getting so many merge conflicts with the project file though. I've been using Xcode (and Project Builder before it) for a long time and at least in recent versions I haven't had much trouble with this. I'm somewhat curious, what version control system are you using?Avisavitaminosis
S
9

Other answers notwithstanding, this is absolutely a departure from other IDEs, and a major nuisance. There's no good solution I know of.

The one trick I use a lot to make it a little more bearable — especially with resource directories with lots of files in them — is:

  • select a directory in the project tree,
  • hit the delete key,
  • choose "Remove References Only", then
  • drag the directory into the project to re-add it.

This clobbers any manual reordering of files, but it does at least make syncing an O(1) operation, instead of being O(n) in the number of files changed.

Salty answered 15/7, 2011 at 21:54 Comment(1)
Good idea. What a pain in the ass, but so are many aspects of developing for iOS.Infant
W
0

I'm intrigued which IDEs you're using that automatically compile everything in a directory, as no IDE I've ever used does that (at least for C++). I think it's pretty standard to have a project file containing a list of all the files. Often you may want to only include certain files for different targets, have per-file compiler settings, etc.

Anyway, given that that's how it does work, you really shouldn't have too many problems from merge conflicts. The best advice would be commit early and often so that you don't get out of step with other people's changes. Merely adding files to the project shouldn't result in a conflict unless they happen to be added at exactly the same point in the project tree. We've been using Xcode in our team for years and we very rarely get conflicts: only if someone has restructured the project.

Fortunately, because the Xcode file format is text, it's generally quite easy to resolve conflicts when they occur, unlike the Bad Old Days of Codewarrior with it's binary format.

We answered 23/2, 2010 at 21:41 Comment(3)
Eclipse works this way, for example. I'm sure there are others - project files are pretty silly - when you typically just want all of the files in your directory structure, with potential ignore filters. That said, it does seem like the conflicts are pretty resolvable.Mychael
Actually many make files for Linux/BSD/etc. systems work that way. Source files are sorted in directories and the make files basically knows that when building target A, it has to compile all files in the folders a, b, and c and link all the resulting .o files together, when building target B, it has to compile all the files in folders b, e, and f. When building two targets at once, the same folder is not built twice, unless the make file has been written that way.Terminate
NetBeans and Visual Studio do this also, most people new to Xcode are likely to be coming from these three IDE's. What I find most annoying about Xcode is moving a file does not move this on disk, so you end up with confusing file structures not matching what is in Xcode. Visual Studio does require files to be added to it, however when a file is moved it moves it on disk also.Torrefy
R
0

One work around that I use is to manually add the files to the project via the Ctrl+Click to the directory or project and select the Add Files to ... designation. Then I manually select the files that are not appearing. Additionally, I add the copy files if needed selection on the selection screen display. Hope this helps.

Rodmann answered 29/5, 2023 at 12:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.