Specific help with an Xcode project template that does not replace in the file contents

We are trying to create a project template, but the documentation on it is spotty or non-existent.

Performing some reverse engineering in some template files, we came to the following: However, this actually does not work!

First of all, we found out that project templates should be installed inside:

~ / Library / Application Support / Developer / Shared / Xcode / Project Templates

We created the project and installed it here, and this part works - we see that it is shown in the "Custom Templates" section in the Xcode New Project editor.

The project folder contains the following files. As you can see, I want the file names to be replaced (this part works), but, as you will see, I also want the contents of the files to be replaced; this does not happen.

  • ___ PROJECTNAME ___. xcodeproj
  • ___ PROJECTNAMEASIDENTIFIER ____ Prefix.pch
  • ___ PROJECTNAMEASIDENTIFIER ___. icns
  • ___ PROJECTNAMEASIDENTIFIER ___ Delegate.h
  • ___ PROJECTNAMEASIDENTIFIER ___ Delegate.m
  • ___ PROJECTNAMEASIDENTIFIER ___ Template.html
  • Debug.xcconfig
  • ru.lproj
  • Info.plist
  • Release.xcconfig

I put two special files in the package ___ PROJECTNAME ___. xcodeproj:

  • TemplateInfo.plist
  • TemplateIcon.icns - the icon displayed in the "New Project" window

If I create a new project (called "Foo and Bar" as a stress test) using this template, these are the files that it creates:

  • Debug.xcconfig
  • en.lproj
  • Foo and Bar.xcodeproj
  • Foo ___ Bar_Prefix.pch
  • Foo ___ Bar.icns
  • Foo ___ BarDelegate.h
  • Foo ___ BarDelegate.m
  • Foo ___ BarTemplate.html
  • Info.plist
  • Release.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", ___ . 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>
+3
6

, "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>
+4
+4

( " ..." ), ...

, ; Foo ___ BarDelegate.m, .

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

#import "___PROJECTNAMEASIDENTIFIER___AppDelegate.h"

@implementation ___PROJECTNAMEASIDENTIFIER___AppDelegate
+3

, : old-style MacRoman UTF-8, . . 3.1 , .

+2

"< < ? xcode .

0

!

For me, adding files to plist works, I changed the html file to a php file and figured it out. But now he analyzes only the first few elements from the list. The old html file is still: "PROJECTNAME" Like this program, the number of elements in the list is not taken into account ...

But where is the place in the code where it does not do this ...?

0
source

Source: https://habr.com/ru/post/1697951/


All Articles