Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
660 views
in Technique[技术] by (71.8m points)

templates - Totally change entire "header" on ALL new files in Xcode

When you create any file in Xcode you get:**

enter image description here

Is there a way to completely CHANGE that template?

(It's trivial to change the corporate name, etc. How to change the actual template?)

I do not care, at all, if I have to redo the change each time Xcode is upgraded.


FYI Years later, correct solution - https://stackoverflow.com/a/57510348/294884

question from:https://stackoverflow.com/questions/20311839/totally-change-entire-header-on-all-new-files-in-xcode

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The file template creation process did not change in Xcode 5 so any information you found for Xcode 4 should also work in Xcode 5. But to answer your question, you have to create a custom file template. Duplicate one of Apple's file templates, which are in Xcode's application bundle. The iOS file templates are in the following location in Xcode 5:

Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File Templates

The rest of Apple's file templates are in the following location in Xcode 5:

Xcode.app/Contents/Developer/Library/Xcode/Templates/File Templates

Selecting the Xcode application from the Finder, right-clicking, and choosing Show Package Contents will take you to the Contents directory inside the application bundle.

Place your copy of the file template in the following location:

/Users/YourUsername/Library/Developer/Xcode/Templates/File Templates/GroupName

GroupName is the name of the category on the left side of the New File Assistant. You can create your own group name or use one of the built-in names. Your file template will appear in the GroupName category.

Now it's time to edit your copy of Apple's file template. Inside the .xctemplate folder you should see the following files for Objective-C file templates:

___FILEBASENAME___.h
___FILEBASENAME___.m

There are triple underscores before and after FILEBASENAME. Open the FILEBASENAME files in Xcode and modify them to suit your needs. In your case that would involve changing the comments at the top of the file.

Whether or not creating custom file templates is practical depends on how many of Apple's file templates you want to duplicate. Duplicating every one of Apple's file templates would be impractical, but duplicating Apple's Cocoa Touch file templates would be more practical.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...