Customize Your File Header in Xcode: Step-by-Step Guide

Customize Your File Header in Xcode: Step-by-Step Guide

This guide will walk you through the simple process of creating custom headers for your .swift files in Xcode. The process is straightforward, so this will be a quick read!

Step 1: Create a IDETemplateMacros.plist File

First, you'll need to create an empty file named IDETemplateMacros.plist in a location that's convenient for you. You can do this using Terminal or directly in Finder with your favorite text editor — whatever works best for you. If you're creating the file in a text editor, like the default TextEdit, make sure the document format is set to Plain Text.

Step 2: Add the Header Template

Next, open the IDETemplateMacros.plist file in your preferred editor and paste in the following content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "https://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>FILEHEADER</key>
    <string> ___FILENAME___
// ___PROJECTNAME___
//
// Created by ___FULLUSERNAME___ on ___DATE___.
// Copyright ? ___YEAR___ ___FULLUSERNAME___. All rights reserved.
//
// Any other text</string>
</dict>
</plist>        

3. Pay Attention to Formatting

Notice the space after <string> before the start of the template — this is intentional. If this space is omitted, the formatting will be incorrect. The header will still work, but it may look off, such as having //SomeClass.swift instead of // SomeClass.swift. Also, note that the first line after <string> should not include the double slashes (//). If you add them, the final file will start with //// SomeClass.swift.

4. Explore Available Macros

You can find the full list of available macros here: Apple's Xcode Help Documentation.

5. Determine Where to Use the Custom Header

The next step is to decide where you'd like to use this custom header. Depending on your choice, you'll need to copy the IDETemplateMacros.plist file to the appropriate directory. Here are the options:

  • Globally for Xcode: ~/Library/Developer/Xcode/UserData/
  • Workspace - shared by all users: <WorkspaceName>.xcworkspace/xcshareddata/
  • Workspace - single user: <WorkspaceName>.xcworkspace/xcuserdata/[username].xcuserdatad/
  • Project - shared by all users: <ProjectName>.xcodeproj/xcshareddata/
  • Project - single user: <ProjectName>.xcodeproj/xcuserdata/[username].xcuserdatad/

6. Use Multiple IDETemplateMacros.plist Files

It's important to note that you can use multiple IDETemplateMacros.plist files simultaneously. For example, you can have one global file in:

~/Library/Developer/Xcode/UserData/        

And another one, say, in:

<ProjectName>.xcodeproj/xcuserdata/[username].xcuserdatad/        

This project-specific file will override the global one.

This is how it looks in reality ??

Part 1


Part 2


Yury Lebedev

? iOS Developer | Swift and Apple Platforms Specialist

6 个月

I don't know why, but after publishing the guide, all code fragments disappear, also not all gif images are available after publication, I also published this guide on Medium, where I did not encounter such problems, there you can find full code examples and all gif images https://medium.com/@quasaryy/customize-your-file-header-in-xcode-step-by-step-guide-b6a1f6514f70

要查看或添加评论,请登录

Yury Lebedev的更多文章

社区洞察

其他会员也浏览了