How to create a new “templates” category on Xcode 4 and use my own file templates there?

余生颓废 提交于 2019-12-04 12:28:43

问题


I would like to start using my own templates for iOS applications. I don't want any significant changes, but simpler things like

  • add/remove some boilerplate code
  • add some pragma mark sections
  • hardcode my company's name and some comments for every file
  • change the indentation
  • etc etc etc

The idea is that we will share these templates when we create apps, but at the same time we want to keep the default template files that Xcode 4 already provides. So, in the following screenshot, how can I add a "CompanyName Application" section that contains exactly the same templates (Navigation-based, View-based etc), but with my own changes?

I found that I can add a folder under /Developer/Library/Xcode/Templates/ or /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/ but I'm a bit confused with what do I need to do exactly. I would really appreciate it if you could help me with that, as I have already messed up my folders twice with no luck. Thanks!


回答1:


This blog post by borealkiss has detailed instructions. For starters:

If you add your own templates, the place you should use is under the following path:

~/Library/Developer/Xcode/Templates/

The problem is that it is quite hard to create a custom template. For example, to copy and paste the built-in template to your place will not show up the template on Xcode 4 until you manually change its identifier in TemplateInfo.plist.




回答2:


I just found this article from Bob McCune "Creating Custom Xcode 4 File Templates" that is exactly what I needed, so I put it here for reference.



来源:https://stackoverflow.com/questions/5975883/how-to-create-a-new-templates-category-on-xcode-4-and-use-my-own-file-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!