banner



How To Add Header File In Xcode

Have you ever wanted to change the standard header comment that Xcode automatically puts at the top of ever new source file you add together to a project? Maybe you just don't like the default or need to include your ain copyright or license text. Xcode ix added a FILEHEADER text macro to let you to do but that.

When y'all add a new source file to Xcode 9 it expands the contents of the FILEHEADER text macro. The default value of this macro gives you the standard file header annotate:

                                                            //  ___FILENAME___                                                                              //  ___PACKAGENAME___                                                                              //                                                                              //  Created by ___FULLUSERNAME___ on ___DATE___.                                                                              //  ___COPYRIGHT___                                                                              //                                                    

You can include any Xcode text macro in the FILEHEADER past adding three leading and abaft underscores (_). The full list of possible text macros is in the Xcode help guide (or come across Help > Xcode Help in Xcode).

To utilize a different format for new files:

  1. Create a plist file named IDETemplateMacros.plist.
  2. Add together an entry in the plist file for the FILEHEADER macro with your format.
  3. Move the plist file into the correct location.

Creating The Text Macro File

Creating the plist file can exist a pain with Xcode. I observe the easiest way, if you practice not have a split up plist editor, is as follows:

  1. Open Xcode simply practice not have any open projects. Close any projects that are open up.
  2. Use File > New File... (⌘North) and choose Property Listing from the file templates.
  3. Name the file IDETemplateMacros.plist and salvage information technology to a temporary location.
  4. Add a new entry to the Root dictionary named FILEHEADER and enter the new format in the value field.
  5. Salvage the file once yous have finished editing.

Text Macro plist

Note: You may find it easier to type your new format into a text editor and and then copy and paste into the plist file (step 4).

Format Examples

A unmarried line showing the default copyright:

Notation that there is a leading infinite but yous practice non include the // for the comment on the start line.

A two line header showing creation appointment and copyright:

                                                            Created                  ___DATE___                                                                              // ___COPYRIGHT___                                                    

A header with some projection and toolchain details:

                                                            Created                  for                  ___PROJECTNAME___                  in                  ___YEAR___                                                                              // Using Swift ___DEFAULTTOOLCHAINSWIFTVERSION___                                                                              // Running on macOS ___RUNNINGMACOSVERSION___                                                    

I am not sure how useful it is only for a projection named TextMacros this gives me:

                                                            // Created for TextMacros in 2017                                                                              // Using Swift 4.0                                                                              // Running on macOS 10.13                                                    

It may be a problems or a feature simply I likewise noticed that changing the FILEHEADER macro has no consequence on .strings files.

Text Macro File Locations

Once you accept your new text macro file move it to the correct location. You tin can override the text macros globally, or for an individual workspace or project. Yous tin also decide to keep the macros for a unmarried user or share it for all users.

The total list of locations that Xcode searches, in social club of priority:

Projection - single user

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

Projection - shared by all users

                                          <ProjectName>.xcodeproj/xcshareddata/                                                    

Workspace - unmarried user

                                          <WorkspaceName>.xcworkspace/xcuserdata/[username].xcuserdatad/                                                    

Workspace - shared by all users

                                          <WorkspaceName>.xcworkspace/xcshareddata/                                                    

Globally for Xcode

                                          ~/Library/Developer/Xcode/UserData/                                                    

So you might create a default IDETemplateMacros.plist in ~/Library/Developer/Xcode/UserData/ and then override information technology with a projection specific template created at the workspace or project level.

Annotation: You may need to create the xcshareddata binder if information technology does not already exist. I find that easiest to do from the control line but if you are using Finder then right-click on the xcodeproj or the xcworkspace file and use Evidence Parcel Contents to navigate.

How To Add Header File In Xcode,

Source: https://useyourloaf.com/blog/changing-xcode-header-comment/

Posted by: palmerrecance.blogspot.com

0 Response to "How To Add Header File In Xcode"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel