2008-10-06 24 views
3

我們正在嘗試製作一個項目模板,但是關於此的文檔很少見或不存在。Xcode Project Template對文件內容沒有進行替換的具體幫助

對一些模板文件做一些逆向工程,我們想出了以下內容。但是,它實際上並沒有工作!

首先,我們已經找到了該項目模板應該往裏裝:

〜/庫/ Application Support /開發/共享/ Xcode中/工程模板

我們已經取得了項目並安裝它在這裏,這部分工作 - 我們看到這個顯示在Xcode「New Project」選擇器的「用戶模板」部分。

項目文件夾包含以下文件。正如你所看到的,我希望文件名被取消(該部分起作用),但正如你將看到的,我還希望替換文件的內容;這不會發生。

  • ___ PROJECTNAME ___。xcodeproj
  • ___ PROJECTNAMEASIDENTIFIER ____ Prefix.pch
  • ___ PROJECTNAMEASIDENTIFIER ___。ICNS
  • ___ PROJECTNAMEASIDENTIFIER ___ Delegate.h
  • ___ PROJECTNAMEASIDENTIFIER ___ Delegate.m
  • ___ PROJECTNAMEASIDENTIFIER ___ Template.html
  • Debug.xcconfig
  • en.lproj
  • 的Info.plist
  • Release.xcconfig

我已經把兩個特殊的文件到___ ___ PROJECTNAME包xcodeproj:

  • TemplateInfo.plist
  • TemplateIcon。 icns - 顯示在新建項目窗口中的圖標

如果我創建一個新的項目中使用這個模板(稱爲「富&酒吧」作爲一個壓力測試),這些都是文件,它創建:

  • Debug.xcconfig
  • en.lproj
  • 富& Bar.xcodeproj
  • 富___ Bar_Prefix.pch
  • 富___ Bar.icns
  • 富___ BarDelegate.h
  • 富___ BarDelegate.m
  • Foo ___ BarTemplate.html
  • Info.plist
  • Release。xcconfig

到目前爲止好!

但看着文件內容,我得到這樣的事情。這裏是富___ BarDelegate.m的內容:

// 
// «PROJECTNAMEASIDENTIFIER»Delegate.m 
// «PROJECTNAME» 
// 
// Created by «FULLUSERNAME» on «DATE». 
// Copyright «ORGANIZATIONNAME» «YEAR» . All rights reserved. 
// 

#import "«PROJECTNAMEASIDENTIFIER»Delegate.h" 


@implementation «PROJECTNAMEASIDENTIFIER»Delegate 

@end 

的明顯的問題是,不知怎的,我做的TemplateInfo.plist錯誤。但是再次注意,我的特殊物品不僅沒有被替代,而且標準物品甚至沒有被替換!所以也許這是一個更深層次的問題。

但有問題的TemplateInfo.plist是我最好的假設,我提出了一些我試過的變化。既沒有工作。

或者:

{ 
    FilesToMacroExpand = (
     "\_\_\_PROJECTNAMEASIDENTIFIER\_\_\_\_Prefix.pch", 
     "en.lproj/InfoPlist.strings", 
     "\_\_\_PROJECTNAMEASIDENTIFIER\_\_\_\_Prefix.pch", 
     "\_\_\_PROJECTNAMEASIDENTIFIER\_\_\_.icns", 
     "\_\_\_PROJECTNAMEASIDENTIFIER\_\_\_Delegate.h", 
     "\_\_\_PROJECTNAMEASIDENTIFIER\_\_\_Delegate.m", 
     "\_\_\_PROJECTNAMEASIDENTIFIER\_\_\_Template.html", 
     "Info.plist" 
    ); 
    Description = "This project builds a cocoa-based \"element\" plugin for Sandvox."; 
} 

或:

{ 
    FilesToMacroExpand = (
     "«PROJECTNAMEASIDENTIFIER»\_Prefix.pch", 
     "en.lproj/InfoPlist.strings", 
     "«PROJECTNAMEASIDENTIFIER»\_Prefix.pch", 
     "«PROJECTNAMEASIDENTIFIER».icns", 
     "«PROJECTNAMEASIDENTIFIER»Delegate.h", 
     "«PROJECTNAMEASIDENTIFIER»Delegate.m", 
     "«PROJECTNAMEASIDENTIFIER»Template.html", 
     "Info.plist" 
    ); 
    Description = "This project builds a cocoa-based \"element\" plugin for Sandvox."; 
} 

更新:我也嘗試添加了 「FilesToRename」 鍵,即使___似乎是自動導致重命名發生。這與plist中內容,以XML格式(因爲有些人擔心的事情,UTF-8的性質 - 是的,這是一個有效的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>Description</key> 
    <string>This project builds a cocoa-based "element" plugin for Sandvox.</string> 
    <key>FilesToMacroExpand</key> 
    <array> 
     <string>«PROJECTNAMEASIDENTIFIER»_Prefix.pch</string> 
     <string>en.lproj/InfoPlist.strings</string> 
     <string>«PROJECTNAMEASIDENTIFIER».icns</string> 
     <string>«PROJECTNAMEASIDENTIFIER»Delegate.h</string> 
     <string>«PROJECTNAMEASIDENTIFIER»Delegate.m</string> 
     <string>«PROJECTNAMEASIDENTIFIER»Template.html</string> 
     <string>Info.plist</string> 
    </array> 
    <key>FilesToRename</key> 
    <dict> 
     <key>___PROJECTNAMEASIDENTIFIER___.icns</key> 
     <string>«PROJECTNAMEASIDENTIFIER».icns</string> 
     <key>___PROJECTNAMEASIDENTIFIER___Delegate.h</key> 
     <string>«PROJECTNAMEASIDENTIFIER»Delegate.h</string> 
     <key>___PROJECTNAMEASIDENTIFIER___Delegate.m</key> 
     <string>«PROJECTNAMEASIDENTIFIER»Delegate.m</string> 
     <key>___PROJECTNAMEASIDENTIFIER___Template.html</key> 
     <string>«PROJECTNAMEASIDENTIFIER»Template.html</string> 
     <key>___PROJECTNAMEASIDENTIFIER____Prefix.pch</key> 
     <string>«PROJECTNAMEASIDENTIFIER»_Prefix.pch</string> 
     <key>___PROJECTNAME___.xcodeproj</key> 
     <string>«PROJECTNAME».xcodeproj</string> 
    </dict> 
</dict> 
</plist> 
+0

丹伍德,當你繼續發現他們時,請在這個問題上追加你自己的未來技巧。你發佈這個問題重新啓發了我自己嘗試這個,我很想聽聽你最終得出的結論。 – pestophagous 2008-10-06 22:41:24

回答

4

你可能想用一個「 FilesToRename「部分。以下內容來自PyObjC Cocoa基於文檔的應用程序模板。它工作正常。

<?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>Description</key> 
     <string>This project builds a Cocoa-based application written in Python that uses the NSDocument architecture.</string> 
     <key>FilesToMacroExpand</key> 
     <array> 
       <string>«PROJECTNAME»_Prefix.pch</string> 
       <string>Info.plist</string> 
       <string>English.lproj/InfoPlist.strings</string> 
       <string>English.lproj/MainMenu.xib</string> 
       <string>English.lproj/«PROJECTNAMEASIDENTIFIER»Document.xib</string> 
       <string>main.py</string> 
       <string>«PROJECTNAMEASIDENTIFIER»Document.py</string> 
       <string>main.m</string> 
     </array> 
     <key>FilesToRename</key> 
     <dict> 
       <key>CocoaAppDocument.py</key> 
       <string>«PROJECTNAMEASIDENTIFIER»Document.py</string> 
       <key>CocoaDocApp_Prefix.pch</key> 
       <string>«PROJECTNAMEASIDENTIFIER»_Prefix.pch</string> 
       <key>English.lproj/CocoaAppDocument.xib</key> 
       <string>English.lproj/«PROJECTNAMEASIDENTIFIER»Document.xib</string> 
     </dict> 
</dict> 
</plist> 
+0

我的文件似乎正在自動更名;我認爲它裏面的內容沒有被處理。 – danwood 2008-10-06 23:27:50

4

另一個資源是Jesse Grosjean的XcodeTemplateFactory。它是免費和開源的,可以爲您節省未來的麻煩。

+0

該鏈接似乎被打破。在http://groups.google.com/group/hogbaysoftware/browse_thread/thread/f8a56455ec1a4e72?pli=1找到該項目 – Buzzy 2012-01-01 02:22:24

2

有兩種樣式的模板,用模板宏定界符進行區分:舊樣式使用UTF-8文件中的MacRoman guillamots,新樣式在整個使用三個下邊條。你不能混合搭配。新的風格只適用於3.1及更高版本,並且您必須使用文件名中的三個下劃線來替換。

3

繼克里斯的答案(‘有兩種樣式的模板......’),你可以找到在另一個平臺模板的新樣式的例子...

以下顯示的例子一些使用三重下劃線的典型替代變量;如果您在Foo ___ BarDelegate.m中使用這些來代替基於guillamot的變量,它應該可以工作。

// 
// ___PROJECTNAMEASIDENTIFIER___AppDelegate.m 
// ___PROJECTNAME___ 
// 
// Created by ___FULLUSERNAME___ on ___DATE___. 
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved. 
// 

#import "___PROJECTNAMEASIDENTIFIER___AppDelegate.h" 

@implementation ___PROJECTNAMEASIDENTIFIER___AppDelegate 
0

爲什麼你錯過那些「< <」像符號?這就是爲什麼xcode不能識別和替換模板標籤的原因。

0

我只是在同一個問題上敲我的頭!

對我來說,添加文件plist的作品,我用php文件改變了html文件,它被解析。 但是現在它只解析列表中的幾個第一項。 舊的HTML文件仍然是:«PROJECTNAME» 喜歡這個節目不計存在列表中的多少項...

但哪裏是在代碼的地方,它沒有做到這一點? ?