Xcode格式预生成代码
我有一种特定的格式,我喜欢将代码放入其中,每次我创建一个新的 UIViewController (或任何其他与此相关的类)时,都会放入来自 Apple 的相同自动生成的代码,在开始之前我必须花 2 分钟清理它,使其按照我想要的方式格式化。
我想知道是否有一种方法可以在 Xcode 中设置它以添加我的格式化代码版本,这样我就不必浪费时间重新格式化。感谢您的帮助!
I have a particular format that I like to put my code in, and every time I create a new UIViewController
(or any other class for that matter), the same auto-generated code from Apple is put in, and I have to spend the 2 minutes cleaning it up to be formatted the way I want it before I can even start.
I was wondering if there was a way to set it in Xcode to add in my version of the formatted code, so that I don't have to waste my time re-formatting. Thanks for the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您将在 /Developer/Library/Xcode/Templates 中找到 Xcode 在创建新文件时使用的所有模板。看看他们,你应该能够轻松地弄清楚这一切是如何表达的。
希望有帮助。
You will find all the templates that Xcode uses when you create new files in /Developer/Library/Xcode/Templates. Have a look in their, you should be able to figure out how it all words easily.
Hope it helps.
XCode 4 改变了模板的工作方式以及模板的位置,因此请小心遵循说明,除非它们引用 XCode 4。您可以在我的 XCode4 自定义存储库中找到一些模板示例以及它们的位置路径:
https://github.com/KiGi/XCode4Customization
系统模板所在路径为:
/Developer/Platforms/iPhoneOS.platform/Developer/Library/ Xcode/Templates/File Templates
不要更改这些,在您自己的库目录中复制并修改:
~/Library/Developer/ Xcode/UserData/File Templates
这些路径也位于 github 上的“WhereToPlaceFiles”RTF 文件中。
XCode 4 changes how templates work, and where templates go, so be careful following instructions unless they refer to XCode 4. You can find a few template examples, and the paths to where they go in my XCode4 customization repository:
https://github.com/KiGi/XCode4Customization
The paths where the system templates live is:
/Developer/Platforms/iPhoneOS.platform/Developer/Library/ Xcode/Templates/File Templates
Don't change those, copy and modify in your own library directory:
~/Library/Developer/Xcode/UserData/File Templates
Those paths are also in the "WhereToPlaceFiles" RTF file on github.
一些选项:
学会接受格式
编写代码来修复它
制作您自己的 UIViewController 模板,使其成为您想要的方式
http://blog. Carbon Five.com/2009/05/19/custom-xcode-template-for-iphone-development/
Some options:
Learn to be ok with the format
Write code to fix it
Make your own UIViewController template that makes it the way you want
http://blog.carbonfive.com/2009/05/19/custom-xcode-template-for-iphone-development/
您可以编写自己的模板(正如其他人详细介绍的那样),和/或只是通过代码格式化程序运行您的源代码(uncrustify 适用于 objc 源)。
you can write your own templates (as others have detailed), and/or just run your sources through a code formatter (uncrustify works well on objc sources).