Fork me on GitHub

修改xcode初始生成代码

xcode在新建新的工程的时候会默认生成一份代码,例如新建一个c++工程,其初始的代码如下:

#include <iostream>

int main(int argc, const char * argv[]) {
    // insert code here...
    std::cout << "Hello, World!\n";
    return 0;
}

 

这本无可厚非,当我们第一次用c++的时候非常友好的代码。Hello World! 只是当写算法题需要大量新建工程时,我们可能希望面对的不是这样一份几乎没用的代码,我们希望的是能够已经写了足够多的库文件或者一些初始注释
啥的。因此此时我们就需要来修改这个初始的文件。

我们找到这个文件的位置: /Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/Project Templates/Mac/Application/Command Line Tool.xctemplate/TemplateInfo.plist

语言类似html风格,我们找到我们需要修改的地方进行修改就好了。主要注意的是它用的是html的语法,因此例如 < > " & 等字符需要转义 例如< 变成> 等等。

最后说一下,上面的几个//的注释不在这个文件里修改。不过也在附近的文件里。如果你觉得看着这个初始的注释信息不顺眼也可以自己去探寻修改一下。

以及xcode更新的时候这个文件可能又会变成初始,因此改完之后最好备份一下。就酱~

另附我修改后的源文件:

<?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>Identifier</key>
    <string>com.apple.dt.unit.commandLineTool</string>
    <key>Ancestors</key>
    <array>
        <string>com.apple.dt.unit.base</string>
        <string>com.apple.dt.unit.osxBase</string>
    </array>
    <key>Concrete</key>
    <true/>
    <key>SortOrder</key>
    <integer>50</integer>
    <key>Description</key>
    <string>This template creates a command-line tool.</string>
    <key>Targets</key>
    <array>
        <dict>
            <key>ProductType</key>
            <string>com.apple.product-type.tool</string>
            <key>TargetIdentifier</key>
            <string>com.apple.dt.commandLineToolTarget</string>
            <key>BuildPhases</key>
            <array>
                <dict>
                    <key>Class</key>
                    <string>Sources</string>
                </dict>
                <dict>
                    <key>Class</key>
                    <string>Frameworks</string>
                </dict>
                <dict>
                    <key>Class</key>
                    <string>CopyFiles</string>
                    <key>DstPath</key>
                    <string>/usr/share/man/man1/</string>
                    <key>DstSubfolderSpec</key>
                    <string>0</string>
                    <key>RunOnlyForDeploymentPostprocessing</key>
                    <string>YES</string>
                </dict>
            </array>
        </dict>
    </array>
    <key>Options</key>
    <array>
        <dict>
            <key>Identifier</key>
            <string>commandLineType</string>
            <key>Name</key>
            <string>Language:</string>
            <key>Description</key>
            <string>The primary implementation language for the command-line tool</string>
            <key>Default</key>
            <string>Swift</string>
            <key>Type</key>
            <string>popup</string>
            <key>Values</key>
            <array>
                <string>Swift</string>
                <string>Objective-C</string>
                <string>C++</string>
                <string>C</string>
            </array>
            <key>Units</key>
            <dict>
                <key>C</key>
                <dict>
                    <key>Nodes</key>
                    <array>
                        <string>main.c:comments</string>
                        <string>main.c:include</string>
                        <string>main.c:main:content</string>
                    </array>
                    <key>Definitions</key>
                    <dict>
                        <key>main.c:include</key>
                        <string>#include <stdio.h>
</string>
                        <key>main.c:main:content</key>
                        <string>// insert code here...
printf("Hello, World!\n");
return 0;
</string>
                    </dict>
                </dict>
                <key>C++</key>
                <dict>
                    <key>Nodes</key>
                    <array>
                        <string>main.cpp:comments</string>
                        <string>main.cpp:include</string>
                        <string>main.cpp:main:content</string>
                    </array>
                    <key>Definitions</key>
                    <dict>
                        <key>main.cpp:include</key>
                        <string>#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <iostream>
#include <cmath>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>

typedef long long ll;
#define rep(i,a,b) for (int i = (a); i <= (b); ++i)
#define rep2(i,a,b) for (int i = (a); i >= (b); --i)

using namespace std;

const int N = 10010;
int ans, n , m, a[N];

</string>
                        <key>main.cpp:main:content</key>
                        <string>
cin >> n >> m;
rep (i, 1, n){
    scanf("%d",&a[i]);
}

ans = 0;

cout << ans << endl;
</string>
                    </dict>
                </dict>
                <key>Objective-C</key>
                <dict>
                    <key>Nodes</key>
                    <array>
                        <string>main.m:comments</string>
                        <string>main.m:include</string>
                        <string>main.m:main:content</string>
                    </array>
                    <key>Definitions</key>
                    <dict>
                        <key>main.m:include</key>
                        <string>#import <Foundation/Foundation.h>
</string>
                        <key>main.m:main:content</key>
                        <string>@autoreleasepool {
    // insert code here...
    NSLog(@"Hello, World!");
}
return 0;
</string>
                    </dict>
                </dict>
                <key>Swift</key>
                <dict>
                    <key>Project</key>
                    <dict>
                        <key>Configurations</key>
                        <dict>
                            <key>Debug</key>
                            <dict>
                                <key>SWIFT_OPTIMIZATION_LEVEL</key>
                                <string>-Onone</string>
                            </dict>
                        </dict>
                    </dict>
                    <key>Targets</key>
                    <array>
                        <dict>
                            <key>SharedSettings</key>
                            <dict>
                                <key>SWIFT_VERSION</key>
                                <string>___DEFAULTTOOLCHAINSWIFTVERSION___</string>
                            </dict>
                        </dict>
                    </array>
                    <key>Nodes</key>
                    <array>
                        <string>main.swift:comments</string>
                        <string>main.swift:include</string>
                        <string>main.swift:main:content</string>
                    </array>
                    <key>Definitions</key>
                    <dict>
                        <key>main.swift:include</key>
                        <string>import Foundation
</string>
                        <key>main.swift:main</key>
                        <dict>
                            <key>Beginning</key>
                            <string></string>
                            <key>End</key>
                            <string></string>
                        </dict>
                        <key>main.swift:main:content</key>
                        <string>print("Hello, World!")
</string>
                    </dict>
                </dict>
            </dict>
        </dict>
    </array>
    <key>Definitions</key>
    <dict>
        <key>*:main</key>
        <dict>
            <key>Beginning</key>
            <string>int main() {</string>
            <key>End</key>
            <string>}</string>
            <key>Indent</key>
            <integer>1</integer>
        </dict>
    </dict>
</dict>
</plist>

 

posted @ 2017-09-03 16:25 ohazyi 阅读(...) 评论(...) 编辑 收藏