Iphone 格式化Objective-C代码

Iphone 格式化Objective-C代码,iphone,objective-c,ios,xcode,Iphone,Objective C,Ios,Xcode,我将Safari中的Objective-C示例剪切并粘贴到Xcode中,但格式变得混乱。我知道我可以为{和\r}执行多个查找和替换,但是否有一个单键修复程序?Xcode选项/插件。 文本编辑插件等 答:我在TextWrangler中创建了一个AppleScript tell application "TextWrangler" activate replace "- (" using "\\r- (" searching in text 1 of text document "untitled

我将Safari中的Objective-C示例剪切并粘贴到Xcode中,但格式变得混乱。我知道我可以为{和\r}执行多个查找和替换,但是否有一个单键修复程序?Xcode选项/插件。 文本编辑插件等

答:我在TextWrangler中创建了一个AppleScript

tell application "TextWrangler"
activate
replace "- (" using "\\r- (" searching in text 1 of text document "untitled text" options {search mode:literal, starting at top:true, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false}
select find window
select text 1 of find window
replace ";" using ";\\r" searching in text 1 of text document "untitled text" options {search mode:literal, starting at top:true, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false}
select find window
replace "{" using "{\\r" searching in text 1 of text document "untitled text" options {search mode:literal, starting at top:true, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false}
select find window
replace "//" using "\\r//" searching in text 1 of text document "untitled text" options {search mode:literal, starting at top:true, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false}
end tell

Control+I
将对您选择的任何文本进行一定程度的格式化。

在Xcode 4中重新缩进可以解决您可能遇到的大多数格式化问题。但是,如果您仍然对结果不满意,您将不得不求助于第三方

我过去经常更改代码格式。我去更新一些旧代码,却发现它是用不推荐的、现在不熟悉的格式编写的


我一直在使用将旧文件调整为新格式。它有很多选项,但仍然缺乏。但是,它应该可以满足大多数情况。

配置xcode的首选项,使选项卡始终缩进。然后使用select all Then选项卡为您提供的任何格式设置。这已经足够好了,可以执行任何涉及到格式设置的操作不是自动的完全是浪费时间。

我使用TextWrangler,它可以选择录制applescript,然后在}之后查找/替换以添加\r;而且-(Control+I或Editor>Structure>Re-Indent)只会这样做:它会重新缩进您的选择。即使这样,它的性能也很一般。