如何将 Xcode 4 代码片段从一台机器传输到另一台机器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5261076/
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 20:25:53  来源:igfitidea点击:

How Can One Transfer Xcode 4 Code Snippets from One Machine to Another

xcodexcode4

提问by Kristopher Johnson

I've got some user code snippets in my Xcode 4 which I would like to copy to another machine and share with other developers. Is there a way to do so?

我的 Xcode 4 中有一些用户代码片段,我想将它们复制到另一台机器上并与其他开发人员共享。有没有办法这样做?

回答by NSSplendid

Ah found it, they are saved at:

啊找到了,它们保存在:

~/Library/Developer/Xcode/UserData/CodeSnippets/

Each one is a plist file. In contrast to Xcode 3 there is now one file per snippet. There is no harm done in renaming them to more useful file names, Xcode will not mind. In fact, my whole CodeSnippets folder is a git repository and many devs share their favorites on github. Mine are at https://github.com/lichtschlag/Xcode-4-Code-Snippets.

每个都是一个 plist 文件。与 Xcode 3 相比,现在每个代码段只有一个文件。将它们重命名为更有用的文件名并没有什么坏处,Xcode 不会介意。事实上,我的整个 CodeSnippets 文件夹是一个 git 存储库,许多开发人员在 github 上分享他们的最爱。我的在https://github.com/lichtschlag/Xcode-4-Code-Snippets

回答by Steven Fisher

As noted by NSSplendid, they're stored in ~/Library/Developer/Xcode/UserData/CodeSnippets/.

正如 NSSplendid 所指出的,它们存储在~/Library/Developer/Xcode/UserData/CodeSnippets/.

You can use Dropbox to sync them; I use this technique to synchronize my key bindings and archives between computers.

您可以使用 Dropbox 来同步它们;我使用这种技术在计算机之间同步我的密钥绑定和档案。

Follow these steps:

按着这些次序:

  1. Quit Xcode.
  2. Move your CodeSnippets directory to your Dropbox. For example, let's say you moved them to ~/Dropbox/CodeSnippets
  3. Let Dropbox upload them.
  4. Pause Dropbox's syncing.
  5. Move them back to where Xcode stores them.
  6. Create a symbolic link into Dropbox: ln -s ~/Library/Developer/Xcode/UserData/CodeSnippets ~/Dropbox/CodeSnippets.
  7. Resume Dropbox syncing.
  8. Relaunch Xcode.
  1. 退出 Xcode。
  2. 将您的 CodeSnippets 目录移动到您的 Dropbox。例如,假设您将它们移动到~/Dropbox/CodeSnippets
  3. 让 Dropbox 上传它们。
  4. 暂停 Dropbox 的同步。
  5. 将它们移回 Xcode 存储它们的位置。
  6. 在 Dropbox 中创建一个符号链接:ln -s ~/Library/Developer/Xcode/UserData/CodeSnippets ~/Dropbox/CodeSnippets
  7. 恢复 Dropbox 同步。
  8. 重新启动 Xcode。

On your other computer:

在您的另一台计算机上:

  1. Quit Xcode.
  2. Let Dropbox download everything, if it hasn't yet.
  3. Pause Dropbox syncing.
  4. Remove your local Xcode user data: rm -R ~/Library/Developer/Xcode/UserData/CodeSnippets.
  5. Move your UserData from Dropbox to Xcode: mv ~/Dropbox/CodeSnippets ~/Library/Developer/Xcode/UserData/CodeSnippets.
  6. Create a symbolic link from your UserData to DropBox: ln -s ~/Library/Developer/Xcode/UserData/CodeSnippets ~/Dropbox/CodeSnippets.
  7. Resume Dropbox syncing.
  8. Relaunch Xcode.
  1. 退出 Xcode。
  2. 让 Dropbox 下载所有内容(如果尚未下载)。
  3. 暂停 Dropbox 同步。
  4. 删除您本地的 Xcode 用户数据:rm -R ~/Library/Developer/Xcode/UserData/CodeSnippets.
  5. 移动你的UserData从Dropbox的Xcode的:mv ~/Dropbox/CodeSnippets ~/Library/Developer/Xcode/UserData/CodeSnippets
  6. 创建从您的 UserData 到 DropBox 的符号链接:ln -s ~/Library/Developer/Xcode/UserData/CodeSnippets ~/Dropbox/CodeSnippets
  7. 恢复 Dropbox 同步。
  8. 重新启动 Xcode。

The convolutions are necessary because Xcode will not follow a symlink, but Dropbox will. Dropbox will treat that symlink exactly as if the directory was actually there.

卷积是必要的,因为 Xcode 不会遵循符号链接,但 Dropbox 会。Dropbox 会完全按照目录实际存在的方式处理该符号链接。

This is not perfect; you will probably have to quit Xcode to have it recognize new snippets.

这并不完美;您可能必须退出 Xcode 才能让它识别新的片段。

I sync my entire UserData directory, which gets me synchronized key bindings, named tabs, font & color schemes and code snippets. To do this, move and ln ~/Library/Developer/Xcode/UserData instead.

我同步了我的整个 UserData 目录,这让我同步了键绑定、命名选项卡、字体和颜色方案以及代码片段。为此,请移动并 ln ~/Library/Developer/Xcode/UserData 代替。

回答by acoomans

I made a Xcode plugin for synchronizing snippets with a git repository.

我制作了一个 Xcode 插件,用于将片段与 git 存储库同步。

With it, you can share snippets on different computers and even among a team.

有了它,您可以在不同的计算机上甚至在团队之间共享片段。

The ACCodeSnippetRepository plugin is available on Alcatrazand Github.

ACCodeSnippetRepository 插件在AlcatrazGithub上可用。

回答by Leszek Zarna

They are located at ~/Library/Developer/Xcode/UserData/CodeSnippets/

它们位于 ~/Library/Developer/Xcode/UserData/CodeSnippets/

It's good practice use version control for that if those snippets are meaningful to you. Than it's sufficient to do periodic commits and push changes to remote branch.

如果这些片段对您有意义,那么最好使用版本控制。定期提交并将更改推送到远程分支就足够了。

回答by Eimantas

I'm not gonna give you exact answer, but rather a guideline: code blocks, completions, project/file templates (from File -> New...) are held in separate files probably somewhere in [~]/Library/Application Support/Developer/Sharedor somewhere else. So my final point is - search through files for snippets or their titles and I am pretty sure you will find a location where all user made code snippets are stored.

我不会给你确切的答案,而是一个指导方针:代码块、完成、项目/文件模板(从文件 -> 新建...)保存在单独的文件中,可能在[~]/Library/Application Support/Developer/Shared某处或其他地方。所以我的最后一点是 - 在文件中搜索片段或其标题,我很确定你会找到一个存储所有用户制作的代码片段的位置。

If that's the case - then just copy over those files to other machine, restart Xcode there and you should be good.

如果是这种情况 - 那么只需将这些文件复制到其他机器上,在那里重新启动 Xcode,你应该会很好。