Coding style 如何更改Xcode 6.1中的花括号样式?

Coding style 如何更改Xcode 6.1中的花括号样式?,coding-style,xcode6,editor,indentation,Coding Style,Xcode6,Editor,Indentation,对于这个问题,以前版本的Xcode有一些答案,但没有一个能满足我的需要 默认情况下,Xcode 6.1默认为缩进的形式,但我更喜欢缩进。现在,我所有的代码片段都是Allman风格的,但是Xcode对于可以实现的函数的自动完成特性仍然将大括号放在函数声明的同一行。例如,如果我创建一个类并编写init,然后让Xcode自动完成,它会将大括号放在同一行上。手动修复并不是什么大不了的事,但这有点拖沓 我如何实现这一功能,即使它很粗糙?我也有同样的挫折感,并开发了一个在一定程度上有帮助的AppleScri

对于这个问题,以前版本的Xcode有一些答案,但没有一个能满足我的需要

默认情况下,Xcode 6.1默认为缩进的形式,但我更喜欢缩进。现在,我所有的代码片段都是Allman风格的,但是Xcode对于可以实现的函数的自动完成特性仍然将大括号放在函数声明的同一行。例如,如果我创建一个类并编写
init
,然后让Xcode自动完成,它会将大括号放在同一行上。手动修复并不是什么大不了的事,但这有点拖沓


我如何实现这一功能,即使它很粗糙?

我也有同样的挫折感,并开发了一个在一定程度上有帮助的AppleScript。Xcode中的文本编辑通过脚本能力很难得到支持,所以我的脚本有一些怪癖。当您在Xcode工作区中打开一个.swift文件时,它似乎工作得最好;当您打开一个要编辑花括号的文件时,它似乎也会更愉快

它只会正确缩进类和func级别的开口大括号,尽管所有其他开口大括号将位于各自的行上。我通常在添加了所有iBaction之后运行它来为我清理它

我将脚本存储在~/Library/Scripts/Applications/Xcode文件夹中,以便轻松访问它

给你,祝你好运:

set oneIndent to space & space & space & space -- Four spaces for indent (see Text Editing Preferences -> Indentation)
set isFirstBrace to true
global oneIndent, isFirstBrace

tell application "Xcode"
    set allDocs to every text document
    set theirNames to the name of every text document
    choose from list theirNames with prompt "Choose your active file:"
    if the result is not false then
        set aName to item 1 of the result
        set c to my FindItemNumber(theirNames, aName)
        set workingDocument to item c of allDocs
        set delegateText to text of workingDocument
        set textParagraphs to every paragraph of delegateText
        set newTextString to {}
        repeat with eachPara in textParagraphs
            if (eachPara as text) contains "{" then
                set end of newTextString to my solveIndent(eachPara as text)
                if isFirstBrace is true then set isFirstBrace to false
            else
                set end of newTextString to (eachPara as text) & return
            end if
        end repeat
        set text of item 1 of workingDocument to (newTextString as text)
    end if
end tell

----------------------
to solveIndent(p)
    set astid to AppleScript's text item delimiters
    set AppleScript's text item delimiters to "{"
    if isFirstBrace is true then
        set newParagraph to (text item 1 of p) & return & "{" & (text item 2 of p) & return
    else
        set newParagraph to (text item 1 of p) & return & oneIndent & "{" & (text item 2 of p) & return
    end if
    set AppleScript's text item delimiters to astid
    return newParagraph
end solveIndent

--------------------------
to FindItemNumber(lst, choice)
    set counter to 1
    repeat with eachOption in lst
        if choice = (eachOption as text) then
            set cc to counter
            exit repeat
        end if
        set counter to counter + 1
    end repeat
    return cc
end FindItemNumber

我隐约记得你进入设置,然后进入编辑器设置,你在那里找到了选项。但是我没有一个Xcode环境需要检查。不,选项不在那里。