目的:希望将XCode默认代码中类似以下代码
if (<#condition#>) {
<#statements#>
}
中的左花括号,替换成下面这种默认格式。
<#statements#>
}
if (<#condition#>)
{
<#statements#>
}
{
<#statements#>
}
XCode4.3中,左花括号分为两种,一种是在文件模版中,比如*.h和*.m文件默认代码中的左花括号。
这种修改参见以下连接:
【转】xcode4自定义文件模板(Creating Custom Xcode 4 File Templates)
另一种,就是if、switch这类代码块中,这类的模版文件路径如下:
/Applications/Xcode.app/Contents/PlugIns/IDECodeSnippetLibrary.ideplugin/Contents/Resources/SystemCodeSnippets.codesnippets
以if代码块为例,在此文件中找到以下代码:
1
<
dict
>
2 < key >IDECodeSnippetVersion </ key >
3 < integer >1 </ integer >
4 < key >IDECodeSnippetCompletionPrefix </ key >
5 < string >if </ string >
6 < key >IDECodeSnippetContents </ key >
7 < string >if ( <#condition# >) {
8 <#statements# >
9 } </ string >
10 < key >IDECodeSnippetIdentifier </ key >
11 < string >D70E6D11-0297-4BAB-88AA-86D5D5CBBC5D </ string >
12 < key >IDECodeSnippetLanguage </ key >
13 < string >Xcode.SourceCodeLanguage.C </ string >
14 < key >IDECodeSnippetSummary </ key >
15 < string >Used for executing code only when a certain condition is true. </ string >
16 < key >IDECodeSnippetTitle </ key >
17 < string >If Statement </ string >
18 < key >IDECodeSnippetCompletionScopes </ key >
19 < array >
20 < string >CodeBlock </ string >
21 </ array >
22 </ dict >
2 < key >IDECodeSnippetVersion </ key >
3 < integer >1 </ integer >
4 < key >IDECodeSnippetCompletionPrefix </ key >
5 < string >if </ string >
6 < key >IDECodeSnippetContents </ key >
7 < string >if ( <#condition# >) {
8 <#statements# >
9 } </ string >
10 < key >IDECodeSnippetIdentifier </ key >
11 < string >D70E6D11-0297-4BAB-88AA-86D5D5CBBC5D </ string >
12 < key >IDECodeSnippetLanguage </ key >
13 < string >Xcode.SourceCodeLanguage.C </ string >
14 < key >IDECodeSnippetSummary </ key >
15 < string >Used for executing code only when a certain condition is true. </ string >
16 < key >IDECodeSnippetTitle </ key >
17 < string >If Statement </ string >
18 < key >IDECodeSnippetCompletionScopes </ key >
19 < array >
20 < string >CodeBlock </ string >
21 </ array >
22 </ dict >
将第7行左花括号左边的空格改成回车即可,完成后如下。
1
<
dict
>
2 < key >IDECodeSnippetVersion </ key >
3 < integer >1 </ integer >
4 < key >IDECodeSnippetCompletionPrefix </ key >
5 < string >if </ string >
6 < key >IDECodeSnippetContents </ key >
7 < string >if ( <#condition# >)
8 {
9 <#statements# >
10 } </ string >
11 < key >IDECodeSnippetIdentifier </ key >
12 < string >D70E6D11-0297-4BAB-88AA-86D5D5CBBC5D </ string >
13 < key >IDECodeSnippetLanguage </ key >
14 < string >Xcode.SourceCodeLanguage.C </ string >
15 < key >IDECodeSnippetSummary </ key >
16 < string >Used for executing code only when a certain condition is true. </ string >
17 < key >IDECodeSnippetTitle </ key >
18 < string >If Statement </ string >
19 < key >IDECodeSnippetCompletionScopes </ key >
20 < array >
21 < string >CodeBlock </ string >
22 </ array >
23 </ dict >
2 < key >IDECodeSnippetVersion </ key >
3 < integer >1 </ integer >
4 < key >IDECodeSnippetCompletionPrefix </ key >
5 < string >if </ string >
6 < key >IDECodeSnippetContents </ key >
7 < string >if ( <#condition# >)
8 {
9 <#statements# >
10 } </ string >
11 < key >IDECodeSnippetIdentifier </ key >
12 < string >D70E6D11-0297-4BAB-88AA-86D5D5CBBC5D </ string >
13 < key >IDECodeSnippetLanguage </ key >
14 < string >Xcode.SourceCodeLanguage.C </ string >
15 < key >IDECodeSnippetSummary </ key >
16 < string >Used for executing code only when a certain condition is true. </ string >
17 < key >IDECodeSnippetTitle </ key >
18 < string >If Statement </ string >
19 < key >IDECodeSnippetCompletionScopes </ key >
20 < array >
21 < string >CodeBlock </ string >
22 </ array >
23 </ dict >
参考资料: http://stackoverflow.com/questions/5120343/xcode-4-with-opening-brace-on-new-line