15

I use xcode 3.2.4 on snow leopard. Today when I tried to save a file on my project I get an error message saying: The document "nameOfFile.m" could not be saved. I tried reinstalling xcode but no luck. The file can be edited with other editors and I see the same behavior on all my projects as well as newly created projects. Any ideas?

Screenshot for error warning

Jayprakash Dubey
  • 35,723
  • 18
  • 170
  • 177
thomdask
  • 997
  • 1
  • 10
  • 18

15 Answers15

17

Simply by rebooting the computer the issue was fixed.

thomdask
  • 997
  • 1
  • 10
  • 18
  • I had this problem after doing a clean re-install of Lion and using Migration Assistant to bring over my user folder, under which all my code is. I had re-booted after re-installing Xcode and before seeing this problem, but after rebooting again, it was resolved. – Christopher Pickslay Feb 20 '12 at 19:01
6

We were having this problem in a lab environment where user files are mounted via NFS. The client machines are running OS X 10.6.7 and the file server is running Debian Linux. After much grief and reading /var/log/syslog on the client machine I discovered it was a subtle file locking / race condition issue with the file system. Evidently, when editing files in a "bundle" (e.g. as in an Xcode project), the OS is using some form of "safe writes" which involves writing transient data atomically to ~/Library/Caches/TemporaryItems/ (which of course is on the NFS mounted system) -- there is a race here that requires proper file locking. We hope we have fixed the problem by changing the nfs_mount options as described in Mounting NFS volumes in OS X

Mayank
  • 8,777
  • 4
  • 35
  • 60
Wayne Cochran
  • 61
  • 1
  • 2
4

I restarted XCode (by a force-quit, not just closing it) and that fixed it for me.

CSawy
  • 904
  • 2
  • 14
  • 25
  • I had the same problem and even can't close XCode (v12.1). After renaming classes I've seen the same messages on every renamed file. Project build also was broken - the same message was shown, and build didn't start. Killing the process and relaunching the XCode helped to cope with that. – Zaur_M Oct 23 '20 at 13:19
3

Not sure why but the temp files ended in a odd state. In "/private/var/folders" I simply removed all the folders and it cleared up the problem

cd /private/var/folders

sudo rm -fR *

Note: never do a "sudo rm" unless you really know what you are doing. It can cause irrecoverable damage

Toon Krijthe
  • 52,876
  • 38
  • 145
  • 202
Kevin M.
  • 31
  • 1
  • 1
  • This cleared it up for me. Tried the other solutions first, this worked, but I searched in those folders and found one that had project files in it and just deleted that one folder. – Cameron Lowell Palmer Aug 28 '17 at 10:50
2

Cleaning the project (Product > Clean), then force quitting Xcode (Command + Option + Escape, select Xcode, click Force Quit) solved the issue for me. I'm not sure if the clean was necessary, but that was what I did. Upon re-opening the project, I let Xcode index the project before doing anything, then did a Build, and all is well.

Adam Eisfeld
  • 1,424
  • 2
  • 13
  • 25
2

Make sure you have you mouse focused on the code area and not the file in the file list.

voodoogiant
  • 2,118
  • 6
  • 29
  • 49
2

Force quiting Xcode for me worked. I would recommend the same.

1

Hey........... even i faced the same problem..... But got the answer...... steps:

  1. reveal in folder the project.
  2. select the file that is locked
  3. select 'GEt Info'
  4. deselect ie uncheck the label 'LOCKED' in the Info.
vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
bharath gangupalli
  • 550
  • 1
  • 7
  • 23
0

1.Right click on that file 2.Go to Show in Finder . 3.Click on get info . 4.Goto Sharing & Permission

Everyone,username,Fetching & selection ----You can choose appropriate read write option.

0

I have face this issue many times. I followed below steps to fixed this.

1. Select file->Show in Finder
2. Copy those file and past different destination.
3. Remove those file from xCode (to selecting show in finder)
4. Then again add those files from other destination to actual location 
5. Clean code and run the code.
Kiran K
  • 919
  • 10
  • 17
0

Another possible reason is that the file you are trying to modify is an alias (i.e. a soft link).

You will have to modify the source file directly in this case.

yi-ji
  • 427
  • 5
  • 8
0

Thanks @Wayne Cochran,

When I use Xcode to save it, I rebooted the machine several times, and all failed.

So I changed to Visual Studio Code to edit and save. Then it's OK.

Just change the file editor

dengApro
  • 3,848
  • 2
  • 27
  • 41
0

I just ran into the same problem, then I noticed I ran out of disk space. You can disable the warning that pops up when you run low on disk space (perhaps not a wise thing to do). I did that a few days ago and was puzzled for a moment when this message appeared. They could've just said "Disk full" or something instead of "cannot save". Anyway if anyone ever runs into this just free up some disk space.

You might be able to save in an external editor because its not also building your app which might use up the little remaining space. It might also be why it worked after rebooting (if OS X cleaned up some cached stuff on reboot) so it seems plausible.

Either that or your HDD might have just crashed. tic....tic....tic.....

Martin
  • 231
  • 2
  • 4
0

This can happen when you are working with a network hard drive (or are on a cloud) and not connected to the network (connection lost)

0

In my Case, the File which was saying document could not be saved was basically Shortcut/Allies of the file present at another place.

I don't know why it was not able to save if it was opened by shortcut/allies in xcode but by overwriting(Copy and Paste) the orignal files to that shortcut my problem was solved.

Regards Umair Bhatti

suraj_fale
  • 978
  • 2
  • 21
  • 53