Xcode:“无法保存文档。您没有权限。”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8051228/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 22:21:48  来源:igfitidea点击:

Xcode: "The document could not be saved. You don’t have permission."

objective-cxcode

提问by Michael

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."

尝试在 Xcode 4 中保存文件时出现此错误:“无法保存文档。您没有权限。要查看或更改权限,请在 Finder 中选择该项目,然后选择文件 > 获取信息。 ”

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

自然地,将文件保存在 TextMate 中可以正常工作。权限:-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).

更新:还尝试复制文件或重命名它们。目录未锁定。顺便说一句,当我在 Xcode 中编辑项目配置时,它保存得很好,我只遇到了保存 .m/.h 文件的问题。我想复制文件中的实际文本会起作用,但我试图找到一个不那么硬核的解决方案(bash 脚本不是问题,但可能还有其他问题)。它也不是最简单的项目(约 70 个文件,编辑过的配置)。

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

更新 2:发现可能重复,并没有真正解决问题Unable to unlock file for edit 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.

更新 3:检出较早的提交,并在打开 Xcode 时表示项目已锁定。再次检出相同的提交,错误不再出现(所有文件 exc. DS_Store 都被跟踪)。什么。

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

更新 4:我创建了一个新用户并将 chmod -R 777 设置为项目目录。现在编辑工作正常。但是我不能让它在我的主帐户下工作(我在这里有我所有的偏好。)

采纳答案by Michael

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) :

对于 Mac OS X v10.5 或更高版本(如果您想保留原始用户名,请执行此操作两次):

  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.
  1. 启用 root 用户
  2. 以 root 身份登录。
  3. 导航到 /Users 文件夹。
  4. 选择要更改短名称的主文件夹,然后像重命名任何文件夹一样重命名它。请记住,短名称必须全部小写,不能有空格,并且只能包含字母。
  5. 使用“系统偏好设置”中的“用户与群组”面板(Mac OS X v10.6.8 或更早版本中的“帐户”面板)使用您在上一步中使用的帐户名称或短名称创建新用户。
  6. 当“用户文件夹中的一个文件夹已经具有名称‘帐户名’。您想将该文件夹用作此用户帐户的主文件夹吗?”时单击“确定”。注意:这将更正 Home 文件夹中所有文件的所有权,并避免内容的权限问题。
  7. 从 Apple 菜单中选择注销。
  8. 以新创建的用户身份登录。您应该能够访问所有原始文件(在桌面上、文档中以及此主页的其他文件夹中)。
  9. 确认您的数据符合预期后,您可以通过“用户和组”窗格(Mac OS X v10.6.8 或更早版本中的“帐户”窗格)删除原始用户帐户。
  10. 禁用 root 用户。

回答by HansPinckaers

Rebooting fixed the error in my case.

在我的情况下,重新启动修复了错误。

回答by Kyle Clegg

Xcode 6 update: still seeing this problem.

Xcode 6 更新:仍然看到这个问题。

Seems like an Xcode bug, because opening the file by clicking the error in the Issue navigatorcauses 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 navigatoror Open quicklyshortcut.

似乎是 Xcode 错误,因为通过单击错误打开文件Issue navigator会导致此问题,但是如果我使用 cmd+shift+O 快捷方式打开文件,我就可以编辑并保存它。所以对我来说,解决方法是不通过选择错误来打开文件,而是使用Project navigatorOpen quickly快捷方式打开它。

回答by J Duncan

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.

我升级到 Lion 并下载了新的 Xcode,发现了同样的问题,但没有找到任何帮助,花了大约三天的时间来修复它。然后我意识到保存在 Applications 文件夹中的 Xcode 4 不会覆盖 Developer 文件夹中的 Xcode 3。当我打开 Xcode 时,我打开的是第 3 版,而不是第 4 版。

Make sure you're opening the right version.

确保您打开了正确的版本。

回答by Krejko

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.

我也刚遇到这个问题。我无法通过更改单个项目文件或文件夹的权限来修复它。但是,我可以通过进入用户主文件夹上的“获取信息”,重新选择用户的“读取和写入”权限,然后单击齿轮->“应用于封闭项目”来修复它。花了一段时间,但一切都按预期进行。希望它可以帮助别人。

回答by ElonChan

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

如果您使用 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).

我正在运行 Xcode 7.3 和 CocoaPods 1.0.0。当尝试从添加为开发 pod(即从本地目录)的 pod 中修改文件时会发生这种情况。

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.

我只是再次 pod 更新,当 pod 完成时,Xcode 会显示一个警告“文档之前有未保存的更改。”,然后单击“重新保存”。这解决了我的问题。

回答by holographix

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

它应该可以解决您的问题