[英]Formatting Objective-C code
我将 Objective-C 示例从 Safari 剪切并粘贴到 Xcode 中,但格式变得混乱。 我知道我可以对 { 和 \r 进行多次查找和替换,但是某处是否有一个按钮修复? Xcode 选项/插件。 TextEdit插件等?
答:我在 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 中重新缩进应该可以解决您可能遇到的大多数格式问题。 但是,如果您仍然对结果不满意,则必须使用 go 第三方。
我曾经经常更改我的代码格式。 我用 go 来更新一些旧代码,却发现它是使用不推荐使用的、现在不熟悉的格式编写的。
我一直在使用Uncrustify将旧文件适应新格式。 它有很多选择,但仍然缺乏。 但是,它应该足以满足大多数情况。
配置 xcode 的首选项,使选项卡始终缩进。 然后 go 与 select-all-then-tab 为您提供格式化。 它已经足够好了,并且做任何涉及非自动格式化的事情都是完全浪费时间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.