12

I tried to create MVVM Template to creating file(s) (not project).

I want to add group (yellow folder) when I create the file, but I can't. When I created it, It create a folder (blue folder).

How can I achieve this?

I tried to use Node and Definitions but it still showing blue folder.

My MVVM.xctemplate hierarchy is like this:

-- (folder) FILEBASENAME FILEBASENAME

---- ___FILEBASENAME___ViewController.swift

--TemplateIcon.png

--TemplateIcon@2x.png

--TemplateInfo.plist

Here is my TemplateInfo.plist file

<?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>An empty MVVM Swift file.</string>
    <key>Summary</key>
    <string>An empty Swift MVVM file</string>
    <key>AllowedTypes</key>
    <array>
        <string>public.swift-source</string>
    </array>
    <key>DefaultCompletionName</key>
    <string>File</string>
    <key>MainTemplateFile</key>
    <string>___FILEBASENAME___.swift</string>
    <key>Platforms</key>
    <array>
        <string>com.apple.platform.iphoneos</string>
    </array>
    <key>Options</key>
    <array>
        <dict>
            <key>Identifier</key>
            <string>productName</string>
            <key>Required</key>
            <true/>
            <key>Name</key>
            <string>Name:</string>
            <key>Description</key>
            <string>The name of the Navigator, ViewController and ViewModel to create</string>
            <key>Type</key>
            <string>text</string>
            <key>Default</key>
            <string>MyModel</string>
        </dict>
    </array>
    <key>Definitions</key>
    <dict>
        <key>___FILEBASENAME___/___FILEBASENAME___ViewController.swift</key>
        <dict>
            <key>Group</key>
            <array>
                <string>___FILEBASENAME___</string>
            </array>
            <key>Path</key>
            <string>___FILEBASENAME___/___FILEBASENAME___ViewController.swift</string>
            <key>TargetIndices</key>
            <array/>
        </dict>
    </dict>
    <key>Nodes</key>
    <array>
        <string>___FILEBASENAME___/___FILEBASENAME___ViewController.swift</string>
    </array>
</dict>
</plist>

Thank you.

Jefferson Setiawan
  • 536
  • 1
  • 5
  • 22

1 Answers1

1

Actually, this is not feasible for now. I also faced the same problem and after extensive research, I came to know that giving dynamic names to folders in the custom template is possible but the files inside the folder are not in the app targets and so you can't use them.

For now, after adding a new module I have performed the following steps to overcome this problem

  • Point to the parent folder, right-click on it, and selects the Add files to option.
  • A popup will appear, choose the root folder of your module and pick Create groups and press the Add button.
  • This will add a custom template inside the project and now we can safely delete the old folder of our module by right click on it, selecting Delete, and picking the option Remove reference.

I have posted this answer so developers don't spend much time in research as I have done.

Indrajeet
  • 5,490
  • 2
  • 28
  • 43