前言
- 本文以
Xcode10
为开发背景
一、找到系统自带代码块源文件
- Xcode5.1之前:
/Applications/Xcode.app/Contents/PlugIns/IDECodeSnippetLibrary.ideplugin/Contents/Resources/SystemCodeSnippets.codesnippets
- Xcode 5.1 - Xcode9:
/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/SystemCodeSnippets.codesnippets
- Xcode10:
/Applications/Xcode.app/Contents/PlugIns/IDESourceEditor.framework/Versions/A/Resources/SystemCodeSnippets.codesnippets
- 打开它之后代码如下
<?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">
<array>
<dict>
<key>IDECodeSnippetVersion</key>
<integer>1</integer>
<key>IDECodeSnippetCompletionPrefix</key>
<string>@protocol</string>
<key>IDECodeSnippetContents</key>
<string>@protocol <#protocol name#> <NSObject>
<#methods#>
@end</string>
<key>IDECodeSnippetIdentifier</key>
<string>986936BB-E0FE-4E7E-9A79-E3C77528204E</string>
<key>IDECodeSnippetLanguage</key>
<string>Xcode.SourceCodeLanguage.Objective-C</string>
<key>IDECodeSnippetSummary</key>
<string>Define an Objective-C protocol.</string>
<key>IDECodeSnippetTitle</key>
<string>Objective-C Protocol Definition</string>
<key>IDECodeSnippetCompletionScopes</key>
<array>
<string>TopLevel</string>
</array>
</dict>
<dict>
<key>IDECodeSnippetVersion</key>
<integer>1</integer>
<key>IDECodeSnippetCompletionPrefix</key>
<string>initialize</string>
<key>IDECodeSnippetContents</key>
<string>+ (void)initialize
{
if (self == [<#ClassName#> class]) {
<#statements#>
}
}</string>
<key>IDECodeSnippetIdentifier</key>
<string>F9022097-FD7D-45DC-A790-A2EA6845386F</string>
<key>IDECodeSnippetLanguage</key>
<string>Xcode.SourceCodeLanguage.Objective-C</string>
<key>IDECodeSnippetSummary</key>
<string>Initialize a class before it receives its first message.</string>
<key>IDECodeSnippetTitle</key>
<string>Objective-C +initialize Method</string>
<key>IDECodeSnippetCompletionScopes</key>
<array>
<string>ClassImplementation</string>
</array>
</dict>
由于篇幅原因,不全显示在这里
二、找到开发者自定义代码块的地址
地址:
~/Library/Developer/Xcode/UserData/CodeSnippets/
注意:只有自己定义过代码块,才会在UserData目录下存在CodeSnippets文件夹,否则是不存在的。
若未自定义过代码块,则可以使用如下方法
Xcode10之前:
选中随意一段代码,按住拖到右下角的{}中,快速填空,即可
-
Xcode10:
另外,查看代码块的位置变成了右上角
-
此时再打开
~/Library/Developer/Xcode/UserData/CodeSnippets/
三、修改系统样式
-
1.找到想要修改的样式,比如
if
代码块
-
2.打开自定义的某.codesnippet文件
四、改改文件名啥的-。-,这个就不写了吧
右键修改文件名了解一下