2

I have been trying to create the Xcode File Template that contains boiler plate files and code structure for MVVM design pattern.

I created a module successfully with custom template using the plist configuration and file structure as below:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>Kind</key>
        <string>Xcode.IDEFoundation.TextSubstitutionFileTemplateKind</string>
        <key>Description</key>
        <string>MVVM Module Template.</string>
        <key>Summary</key>
        <string>MVVM Module Template</string>
        <key>Options</key>
        <array>

            <dict>
                <key>Identifier</key>
                <string>productName</string>
                <key>Required</key>
                <true/>
                <key>Name</key>
                <string>Module Name:</string>
                <key>Description</key>
                <string>The module name.</string>
                <key>Type</key>
                <string>text</string>
                <key>Default</key>
                <string>Base</string>
            </dict>

            <dict>
                <key>Identifier</key>
                <string>View</string>
                <key>Name</key>
                <string>Also create View file for user interface</string>
                <key>Description</key>
                <string>Create a view file with the same name</string>
                <key>Type</key>
                <string>checkbox</string>
                <key>NotPersisted</key>
                <true/>
            </dict>

        </array>
    </dict>
</plist>

Folder Structure For the Custom Template

The problem was that, when I checked the checkbox, all the files in the View folder was created, but when checkbox is not checked, non of the files are created.

What shall I do to achieve following cases:

  • Generate source files from the folder 'Source' when checkbox is unchecked.
  • Generate source files from the folder 'View' when checkbox is checked.
Ranxan
  • 21
  • 5
  • Some links I referred to get started with custom XCode Templates: - https://github.com/NSBoilerplate/Xcode-Project-Templates/wiki/Creating-Xcode-4.x-Project-Templates - https://medium.com/@dima.cheverda/xcode-9-templates-596e2ed85609 – Ranxan May 07 '18 at 12:05
  • 1
    Solution to this issue would be, rename the Source folder to Default. https://stackoverflow.com/questions/49813980/xcode-custom-template-folder-structure-for-only-a-checkbox-where-to-put-varia – Morten Gustafsson Apr 30 '19 at 20:34

1 Answers1

2

You're doing it right for when the checkbox is checked, but you need to change the "Source" to "default" for when the checkbox is unchecked.

julian.a
  • 1,163
  • 2
  • 9
  • 21