美文网首页iOS UI
修改Xcode系统自带代码块样式

修改Xcode系统自带代码块样式

作者: 风月灯 | 来源:发表于2018-10-02 20:59 被阅读60次

前言

  • 本文以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 &lt;#protocol name#&gt; &lt;NSObject&gt;

&lt;#methods#&gt;

@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 == [&lt;#ClassName#&gt; class]) {
        &lt;#statements#&gt;
    }
}</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:


    图1:选中->右键

    另外,查看代码块的位置变成了右上角


    图2:代码块位置
  • 此时再打开~/Library/Developer/Xcode/UserData/CodeSnippets/

    图3:.codesnippet文件

三、修改系统样式

  • 1.找到想要修改的样式,比如if代码块

    图4:找到想改的代码块
  • 2.打开自定义的某.codesnippet文件


    图5:修改copy过来的代码

四、改改文件名啥的-。-,这个就不写了吧

右键修改文件名了解一下

相关文章

网友评论

    本文标题:修改Xcode系统自带代码块样式

    本文链接:https://www.haomeiwen.com/subject/fluaoftx.html