簡體   English   中英

帶有自定義項目模板的 Xcode 9 文件夾引用

[英]Xcode 9 folder references with custom project template

在 Xcode 9 中,當您創建一個組時,它也會在文件系統中創建一個鏈接文件夾。 所以你不需要手動為每個組創建文件夾。 關於 Xcode 9 中組和文件夾相關更改的一個很好的解釋,請參閱此

我有一個自定義 Xcode 項目模板,它生成一個項目並在自定義文件夾中添加大量 Swift 樣板源文件。 我的問題是我只能創建這樣的組文件夾: 在此處輸入圖片說明 , 表示與文件系統目錄無關的組。 這不好,因為如果您以后在 Xcode 中重命名文件夾,它將對相應的文件系統目錄沒有影響。

我的目標是編寫一個 Xcode 項目模板,將我的自定義樣板 swift 文件添加到真正的參考文件夾中,如下所示: 在此處輸入圖片說明 .

你可以從這里下載我的簡化模板,把它放在:~/Library/Developer/Xcode/Templates

然后 Xcode > File > New > Project,然后選擇 Custom-Template。

模板信息.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.Xcode3.ProjectTemplateUnitKind</string>
    <key>Concrete</key>
    <true/>
    <key>Identifier</key>
    <string>custom-swift.xcodeTemplate</string>
    <key>Description</key>
    <string>Swift starter project for iOS projects</string>
    <key>Ancestors</key>
    <array>
        <string>com.apple.dt.unit.cocoaTouchFramework</string>
    </array>
    <key>Nodes</key>
    <array>
        <string>Classes/Interfaces/CustomInterface.swift</string>
    </array>
    <key>Definitions</key>
    <dict>
        <key>Classes/Interfaces/CustomInterface.swift</key>
        <dict>
            <key>Group</key>
            <array>
                <string>Classes</string>
                <string>Interfaces</string>
            </array>
            <key>Path</key>
            <string>Classes/Interfaces/CustomInterface.swift</string>
        </dict>
    </dict>
</dict>
</plist>

它創建了一個這樣的項目:

在此處輸入圖片說明

我想達到的目標:

在此處輸入圖片說明

任何幫助深表感謝! :)

更新 1:

我找到了一個小的解決方法.. 使用模板腳本創建您自己的復雜文件夾層次結構,然后簡單地刪除根文件夾 - 在我的例子中是“類”。 然后打開垃圾箱並將其拖回 Xcode,選擇“如果需要復制項目”並選擇“創建組”。 它將使用真實的參考文件夾構建文件夾結構。

這是您需要做的。 在命名文件之前在節點部分指定組。

<key>Nodes</key>
<array>
<string>MyGroup/File.swift:comments</string>
<array>

接下來在定義中提供鍵中的組名,如下所示:

<key>Definitions</key>
<dict>
<key>MyGroup/File.swift</key>
<dict>
<key>Path</key>
<string>File.swift</string>
<key>Group</key>
<string>MyGroup</string>
</dict>

希望這會有所幫助。

為此,可以使用 imessages 模板中使用的組件

組件的例子是

<key>Components</key>
    <array>
        <dict>
            <key>Identifier</key>
            <string>com.apple.dt.unit.messagesextensioncomponentios</string>
            <key>Name</key>
            <string>___PACKAGENAME___ MessagesExtension</string>
            <key>ProductBuildPhaseInjections</key>
            <array>
                <dict>
                    <key>TargetIdentifier</key>
                    <string>com.apple.dt.messagesOnlyApp</string>
                </dict>
            </array>
        </dict>
    </array>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM