Search code examples
xcodemacostemplatesxcode4plist

Xcode 4 Templates—How to add license to beginning of file?


enter image description here I've spent hours trying to figure this out. In my custom Xcode 4 template, I have a checkbox option to include the zlib/libpng license at the top of each source file. Trouble is, no matter what I do I can't make it tack it on to the beginning of the file AND keep the rest of the file. It either shows // THIS IS A TEST and nothing else, or the whole file but not the test comment.

I've tried what is shown in the screenshot above and dozens of other things. Help!


Solution

  • enter image description here

    I figured it out, finally. As you can see in the image above, for every source file I have two rules, :comments and :content. In the Definitions, I set the :content of each to the rest of the file (all in a big string), and in the option i set just the comments of every file depending on whether the checkbox is checked or not. Since the definitions for the files are now strings, not paths, I had to keep the dictionaries for the header files just to keep the <key>TargetIndices</key> <array/> so they don't get added to the Copy Bundle Resources build phase.