Reputation: 2353
I am using Xcode to code C++. Whenever I create a new project, the default code template is
#include <iostream>
int main(int argc, const char * argv[]) {
// insert code here...
std::cout << "Hello, World!\n";
return 0;
}
I want to change it into something else. How can I do this?
Thanks in advance.
Upvotes: 2
Views: 1173
Reputation: 2353
So emm.. thanks to the encouragement of @Alan Birtles. I now know how to do this.
First, we need to find where the default templates are. Go to this directory
/Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/Project\ Templates/Mac/Application/Command\ Line\ Tool.xctemplate
I use Xcode to mostly code C++ codes, so I am only changing the command line tool templates. But I think this works for all kinds of tools. Now that you are in this directory, you should see a file named:
TemplateInfo.plist
This is the file you should change. Open this file with a test editor. In my case, I used atom to make changes to this file. This file is written in a special syntax(that I didn't understand) Try to understand the basic syntax and change this as the way you like. Here's how I changed the default C++ part:
<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> //changes start from here
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <iostream>
#include <cmath>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
using namespace std;//changes end here
</string>
<key>main.cpp:main:content</key>
<string>// insert code here...
std::cout << "Hello, World!\n";
return 0;
</string>
</dict>
</dict>
Save the changed file and try to create a new command line project. It works great.
ps.Do copy the file before you make any changes in case you mess it up, if you changed it in the wrong way and didn't make a copy of that file, there's a chance that you won't be able to create a project.
Upvotes: 1