我们正在尝试制作一个项目模板,但相关文档参差不齐或不存在。
对一些模板文件进行一些逆向工程,我们得出了以下结果。然而,它实际上不起作用!
首先,我们已经弄清楚项目模板应该安装在里面:
~/库/应用程序支持/开发人员/共享/Xcode/项目模板
我们已经制作了项目并将其安装在此处,并且这部分可以正常工作 - 我们看到它显示在 Xcode“新项目”选择器的“用户模板”部分中。
项目文件夹包含以下文件。正如您所看到的,我希望替换文件名(该部分有效),但正如您将看到的,我还希望替换文件的内容;这不会发生。
- ___PROJECTNAME___.xcodeproj
- ___PROJECTNAMEASIDENTIFIER____Prefix.pch
- ___PROJECTNAMEASIDENTIFIER___.icns
- ___PROJECTNAMEASIDENTIFIER___Delegate.h
- ___PROJECTNAMEASIDENTIFIER___Delegate.m
- ___PROJECTNAMEASIDENTIFIER___Template.html
- 调试.xcconfig
- en.lproj
- 信息.plist
- 发布.xcconfig
我已将两个特殊文件放入 ___PROJECTNAME___.xcodeproj 包中:
- TemplateInfo.plist
- TemplateIcon.icns - 在“新建项目”窗口中显示的图标
如果我使用此模板创建一个新项目(称为“Foo & Bar”作为压力测试),则它创建的文件如下:
- 调试.xcconfig
- en.lproj
- Foo 和 Bar.xcodeproj
- Foo___Bar_Prefix.pch
- Foo___Bar.icns
- Foo___BarDelegate.h
- Foo___BarDelegate.m
- Foo___BarTemplate.html
- 信息.plist
- 发布.xcconfig
到目前为止一切顺利!
但是查看文件内容,我得到了这样的信息。以下是 Foo___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”键,尽管 ___ 似乎会自动导致重命名发生。这是 XML 格式的 plist 内容(因为有些人担心事物的 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>
最佳答案
您可能想要使用“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>
关于cocoa - 有关未在文件内容中进行替换的 Xcode 项目模板的特定帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/176373/