Xcode文件/文件夹模板,非工程

12
我试图创建MVVM模板以创建文件(而不是项目)。
我想在创建文件时添加组(黄色文件夹),但我做不到。当我创建它时,它会创建一个文件夹(蓝色文件夹)。
我该如何实现这一点?
我尝试使用Node和Definitions,但仍然显示蓝色文件夹。
我的MVVM.xctemplate层次结构如下:
-- (文件夹) FILEBASENAME FILEBASENAME
---- ___FILEBASENAME___ViewController.swift
--TemplateIcon.png
--TemplateIcon@2x.png
--TemplateInfo.plist
这是我的TemplateInfo.plist文件
<?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>
谢谢你。

你找到任何解决方案了吗? - JERC
还没有@JERC,但仍然希望能得到解决方案。 - Jefferson Setiawan
还没有解决方案吗? - Neil Faulkner
我猜它只能在项目模板中使用 :( - DanSkeel
1个回答

1

实际上,现在这是不可行的。我也遇到了同样的问题,在进行了广泛的研究后,我发现在自定义模板中给文件夹命名是可能的,但是文件夹内的文件不在应用程序目标中,因此您无法使用它们。

目前,添加新模块后,我已执行以下步骤来解决此问题:

  • 指向父文件夹,右键单击它,并选择添加文件到选项。
  • 将弹出窗口,选择您的模块的根文件夹并选择创建组,然后按添加按钮。
  • 这将在项目中添加一个自定义模板,现在我们可以通过右键单击它,选择删除,并选择删除引用选项来安全地删除我们模块的旧文件夹。

我发布了这个答案,以便开发人员不要像我一样花费太多时间进行研究。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接