Change copyright / top-comment / “header” on ALL n

2019-01-16 07:16发布

When you create any file in Xcode5, the top of the file looks like this:

enter image description here

Is there a way to CHANGE that template or creation so that it looks different?

When I say "change" here's an example of what it could be:

enter image description here

Please note, I do know how to change the name, product name, corporate name, etc. I want to know how to change the actual "template" itself.

(If it is possible.)

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

  2. This is only regarding Xcode 5. Not Xcode 4.

  3. I already know how to change the name and other individual items; I want to change the whole "template" overall

I appreciate this many be simply impossible or may be impractical (maybe you have to change dozens of files, or some such). If that's the case I profoundly appreciate the info, thanks.

Please note: I've noticed on the net, every time someone asks this question, many people answer by explaining how to make "new templates" in Xcode. For example, a new template for a new type of class or category. (It could be that as soon as people see the word "template" they immediately start typing an explanation of how to add a new "template" in that sense.) To be clear the only thing I am asking is, how to change the "standard text" or "copyright text" at the top of the page - all pages - that's it.

(It's hard to know how to refer to the text shown in the two images above .. if you say "header" it makes one think of a .h file; on the other hand it's not really a copyright notice as the copyright is just part of it. i guess it's the "top of file comments block". But it's impossible to google on because of the mix with other terms.)

2条回答
混吃等死
2楼-- · 2019-01-16 08:05

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.

查看更多
Juvenile、少年°
3楼-- · 2019-01-16 08:09

There's a post here with a detailed guide. To access the original templates, you'll need to open the Xcode app bundle as mentioned in Mark's answer.

http://meandmark.com/blog/2011/11/creating-custom-xcode-4-file-templates/

查看更多
登录 后发表回答