How to refresh Project Navigator content in Xcode?
Asked Answered
C

6

48

I'm not able to refresh file list in Project Navigator. There is no refresh button, and I don't think restarting Xcode should be the solution.

How do you see files that you add externally? I'm on Mac.

Calyptrogen answered 17/9, 2012 at 6:58 Comment(1)
I'm adding files externally (for example copy/paste a .js into the same folder). It appears in Xcode after close and reopen, no way to find it in the list otherwiseCalyptrogen
O
41

How do you see files that you add externally?

Files cannot be added externally. Dumping a source file into the project directory does not add it to the project. To add a file you must add it to the project from within Xcode; for example, by using Add Files to "projectname"... from the File menu.

If you have a bunch of files that you need to add then in the Add File dialog you can just select all the files you want at once and add them, without having to repeatedly open the Add File dialog. Just use control clicking to select multiple files.

Orvil answered 17/9, 2012 at 7:55 Comment(10)
Apple - this seems like a very silly design decision based on every other IDE have ever used! Is this really the reason?Virelay
This isn't necessarily true: you can add a folder reference to the project, and Xcode is supposed to show all the entries in that folder (they are all added to the project). This is useful if you have a src directory managed by version control; updates that add files are supposed to be automatically reflected in the project navigator.Menendez
@Menendez I tried this out a while ago and IIRC not only do source files in folder references not automatically get added to targets, they cannot even be added manually to targets; Source files in a folder reference cannot be compiled normally by Xcode. From my reading, folder references are intended for resource files (e.g., images), rather than source files.Orvil
This is absolutely maddening, what possible benefit could there be to maintaining a separate partial file structure of the one on the file system?Collie
@Collie it's down to the philosophy of the build system. Some actively support the practice of just compiling whatever source happens to be in a location and some discourage it. In my experience it causes problems (e.g., like this: reddit.com/r/cpp/comments/524844/recommend_a_build_system/…) so I don't mind Xcode not supporting it here.Orvil
@Orvil the build sources for a target are configured explicitly so I'm not sure how this relates to the filesystem/project navigator.Collie
@Collie "the build sources for a target are configured explicitly" isn't that the separate partial file structure you called maddening? As opposed to the build system not maintaining its own list of files and just building whatever it finds on disk?Orvil
@Orvil so there's 3 things, the filesystem, the file organisation shown in the navigator (which is xcodes own view of how files are organised) and then the build sources which are configured in the project targets. My frustration is with the navigator file organisation being different from the filesystem. AFAIK every single other editor on the market shows the file system in the navigator. For instance if I move or rename files in the terminal I don't expect to have to manually apply the same changes within xcode as well.Collie
@Collie Visual Studio's solution explorer doesn't automatically mirror the file system. Code::Blocks does seem to want the project navigator to match the filesystem but doesn't track when I rename a file outside the IDE, the file link in the navigator just gets broken. Does Qt-Creator or CLion track external changes? I certainly wouldn't expect a target to track one of its source files being renamed externally so that it automatically gets compiled under the new name.Orvil
I've not used any of the editors you've mentioned, I think the only time I've seen an editor that works this way was Borland JBuilder, I still remember the relief of being able to work with the filesystem directly when moving to Eclipse (this is going back a long long time). Since then I've used Textmate, Sublime, Vim, Emacs, VSCode, all of which give you a view of the filesystem. The build system for all of the languages I've used has been cli/file based and having an IDE in the way feels very clunky (not to mention buggy). It looks like I'll just have to learn to live with it.Collie
S
17

Close and reopen the project, if necessary.


This may be required if you are using folder references (as one example). In that case, touching the directory might work to refresh what Xcode displays.

Sonasonant answered 17/9, 2012 at 7:10 Comment(1)
This is the right answer. I find that the folder reference eventually catches up with reality, but it can take some time. If you want it done right away, there's nothing else but to close and open. I suspect this has something to do with the file system changing in memory but those changes not making it to disk right away.Menendez
S
3

File > Add files to "Runner" 👍

Scorpio answered 19/6, 2021 at 18:27 Comment(0)
H
2

For a single file, you can open the external file in Xcode and cmd+s to save it, it will be refreshed in Xcode.

Also, for the quick way you can just chose the external folder in Xcode and cmd+s, it will refresh all your external file in this folder.

Harms answered 13/12, 2013 at 4:4 Comment(1)
This did not work for me. I had files that I deleted and added from the folder directly, and there was nothing to save in Xcode, because it did not detect the changes.Areopagite
A
0

I don't think you can refresh the Project navigator to detect files that have been modified outside of Xcode, and that instead you need to manually add or delete files from the Project navigator with "right-click" / two-finger tap.


Some other solutions suggested:

  • File > Add Files to "Runner"... but that doesn't delete files
  • Open and close Xcode, but that's not practical. It also did not work for me.
  • Use cmd+s, but Xcode does not detect files which need to be saved. And so, that also did not work for me.
Areopagite answered 22/11, 2021 at 7:41 Comment(0)
L
-6

You can just press "Command + B", for refresh your project in xcode

Lesleylesli answered 6/5, 2020 at 7:26 Comment(1)
No, that just builds your project. It will not update the files shown in the project navigator.Areopagite

© 2022 - 2024 — McMap. All rights reserved.