1

我正在开发一个在 Emacs 中编辑但在 Xcode 中调试的 iOS 项目。我偶尔会不小心在 Xcode 中编辑源文件,所以我想防止这种情况发生。我不能让文件本身只读,因为我需要编辑它们。有没有办法让 Xcode 编辑器将它们视为只读并阻止我编辑它们?

我偶尔会使用 Xcode 来编辑项目,例如添加和删除文件。我想阻止编辑文件只是 Xcode 的文件编辑器。所以,我需要一些只适用于文件编辑器的东西,或者可以很容易地打开和关闭的东西。

4

3 回答 3

0

只需打开终端并锁定源文件。

chmod a-w source_folder

Here is youtube screencast: http://youtu.be/tB-BhqlDAdE

Works exactly like what you expected !

于 2013-04-03T17:15:55.940 回答
0

You could give the source folder readonly permissions for your GUI login user and read-write permissions for some other user you just use for terminal/emacs sessions.


Edit:

Comments:

i use my emacs to do lots of other things that i want to keep doing as my normal user, though. i also occasionally do want Xcode to edit the project, e.g. adding and removing files. it's just Xcode's file editor that i want to prevent from editing files.

Okay then lets flip my solution: Run Xcode as a different user that only has readonly access:

!#/bin/bash
su readonlyuser
/Applications/Xcode.app/Contents/MacOS/Xcode

And then use emacs from your normal session. If you need Xcode to have readwrite access you'll need to quit it and re-open it normally. It's a pain but I can't think of any way around it besides some sort of nifty menu bar app that toggles the permissions on the folder to give your readonlyuser write access. You should also give the readonlyuser readwrite access to the xcodeproj bundle and any other Xcode project metadata.

To make this a little less ugly you could wrap that bash script in an AppleScript or Automator Action, export it as an application, and give it the same icon as Xcode but with a little indicator so you know it's the readonlyuser one. Then you can stick it in your dock or whatever.

于 2013-04-03T17:44:41.717 回答
0

Xcode does not have a readonly browsing mode!

To prevent yourself from accidentally modifying files:

  1. Create a disk image of your project directory by using the Disk Utility.

  2. Mount the disk image file.

  3. Open the project from the disk image file.

This way you can't accidentally modify your original source files while browsing them with Xcode.

于 2020-06-30T06:05:13.973 回答