簡體   English   中英

格式化 Objective-C 代碼

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM