Xcode: “The document could not be saved. You don’t

2020-03-14 07:11发布

问题:

I'm getting this error when trying to save a file in Xcode 4: "The document could not be saved. You don’t have permission. To view or change permissions, select the item in the Finder and choose File > Get Info."

Naturally, saving the file in TextMate works fine. Permissions: -rw-r--r--

Nothing changed from when it worked the last time. Files are not locked, I tried rebooting, disk space is ok, files are on a local drive, error was googled. Any ideas?

Thanks.

Update: Also tried copying the files or renaming them. Directories are not locked. By the way, when I edited project configuration in Xcode it saves fine, I only met with the issue saving .m/.h files. I guess that copying the actual text in the files would work but I'm trying to find a bit less hardcore solution (bash script wouldn't be the issue but there could be other problems). It's not the simplest project either (~70 files, edited config).

Update 2: Found possible duplicate, doesn't really resolve the problem Unable to unlock file for editing in Xcode 4?

Update 3: Checked out earlier commit and when opening Xcode it said the project is locked. Checked out the same commit again and the error does not appear again (all files exc. DS_Store are tracked). What.

Update 4: I created a new user and set chmod -R 777 to the project directory. Editing now works fine. However I can't get it to work under my main account (I have all my preferences here.)

回答1:

Rebooting fixed the error in my case.



回答2:

Fixed by changing account name by following this guide. This essentialy creates a new account but with your old Home directory and within the process of transferring it fixes some file permissions.

(From above link:)

For Mac OS X v10.5 or later (do this twice if you want to keep your original username) :

  1. Enable the root user.
  2. Log in as root.
  3. Navigate to the /Users folder.
  4. Select the Home folder with the short name you want to change, and rename it just like you would rename any folder. Keep in mind that the shortname must be all lowercase, with no spaces, and only contain letters.
  5. Use the Users & Groups pane (Accounts pane in Mac OS X v10.6.8 or earlier) in System Preferences to create a new user with the Account name or Short Name that you used in the previous step.
  6. Click OK when "A folder in the Users folder already has the name 'account name'. Would you like to use that folder as the Home folder for this user account?" Note: This will correct the ownership of all files in the Home folder, and avoid permissions issues with the contents.
  7. Choose Log Out from the Apple menu.
  8. Log in as the newly created user. You should be able to access all of your original files (on the desktop, in Documents, and in the other folders of this Home).
  9. After verifying that your data is as expected, you can delete the original user account via the Users & Groups pane (Accounts pane in Mac OS X v10.6.8 or earlier).
  10. Disable the root user.


回答3:

Xcode 6 update: still seeing this problem.

Seems like an Xcode bug, because opening the file by clicking the error in the Issue navigator causes this problem, but if I open the file using the cmd+shift+O shortcut I am able to edit and save it. So for me the workaround is to not open the file by selecting the error and to open it using the Project navigator or Open quickly shortcut.



回答4:

I upgraded to Lion and downloaded the new Xcode and found the same problem and found nothing to help, losing about three days trying to fix it. Then I realized that the Xcode 4, which is saved in the Applications folder, doesn't overwrite Xcode 3, which is in the Developer folder. When I was opening Xcode, I was opening version 3, not 4.

Make sure you're opening the right version.



回答5:

open up the terminal and set

 chmod 777

to the desired file or set

 chmod -R 777

to the desired directory.

it should solve your problem



回答6:

I just ran into this issue also. I was not able to fix it not by changing the permissions of the individual project file or folder. However, I was able to fix it by going into 'get info' on my user's home folder, reselecting the 'Read & Write' permissions for my user, and then clicking the gear->'apply to enclosed items'. Took it a while but then everything worked as expected. Hope it helps someone else.



回答7:

This maybe helpful If you use CocoaPods: https://stackoverflow.com/a/38885499/3395008

I'm running Xcode 7.3 and CocoaPods 1.0.0. and this happens when trying to modify a file from a pod added as a development pod (i.e. from a local directory).

I just pod update again, when pod finished, Xcode will show an alert "The document has previously unsaved changes.", then click "Re-Save". that fix my issue.