In Objective C, when using
在Objective C中,當使用
// MARK: Line In Sand
The default project will produce a menu items with the word "MARK:" in it, or in other words:
默認項目將生成一個包含“MARK:”字樣的菜單項,或者換句話說:
Just recently I downloaded a sample project in Swift (vs ObjC) "ViewControllerPreview" from Apple and the // MARK: Line In Sand only showed "Line In Sand" (no "MARK") when using the aforementioned mark comment style. How'd they do that!? Is that just a basic improvement not applied to anything but Swift?
就在最近,我在Swift (vs ObjC)下載了一個示例項目來自蘋果的“ViewControllerPreview”和// MARK:在使用上述的MARK注釋風格時,沙中的線只顯示“沙中的線”(沒有“標記”)。他們怎么做到的?這僅僅是一個基本的改進嗎?
0
If you're in Objective-C, use this syntax:
如果你在Objective-C中,使用以下語法:
#pragma mark Line In Sand
0
It turns out that the pre-processor in Swift makes special allowance for the
事實證明,Swift的預處理器會為其提供特殊的補貼。
// MARK:
syntax, while the Objective C pre-processor sees this and makes no allowance for special handling. This could be alleviated by Apple by omitting the "MARK:" from the menu just as is done with the #pragma version but no joy.
語法,而Objective C預處理器看到了這一點,不考慮特殊處理。蘋果可以通過從菜單中刪除“MARK:”來緩解這一問題,就像#pragma版本的菜單一樣,但是沒有樂趣。
And on a related note, it turns out the Swift (not ObjC) pre-processor also knows how to add a divider line in automatically so:
與此相關的是,Swift(不是ObjC)預處理器也知道如何自動添加分隔線:
// MARK: - Line In Sand
produces not only a divider line but the 'markless' menu item as well... but only in Swift.
不僅生成分隔行,還生成“無標記”菜單項……但是只有在斯威夫特。
0
Fixed in Xcode 8. Now both Swift and ObjC parsing of comments produce equally pleasing results :
固定在Xcode中8。現在,對評論的快速解析和ObjC解析都會產生同樣令人愉快的結果:
// MARK: - Line in Sand
//馬克:-沙子里的線
Suppresses the "MARK" and you only get the divider and the "Line in Sand"
壓制“標記”,你只能得到分隔符和“沙線”
0
In Xcode 8.3, Apple finally fixed // MARK:
convention for marking sections of code in Objective C so it no longer showed the word "MARK" in the menu.
在Xcode 8.3中,蘋果最終確定了//標記:在Objective C中標記代碼段的約定,因此在菜單中不再顯示單詞“MARK”。
The Objective C #pragma mark -
was inconsistent with other code marking mechanisms such as // ???:
, // !!!:
, // FIXME:
, and others. The fact that // MARK:
was implemented cleanly in Swift and half-implemented in ObjC was inconsistent in Xcode itself until Xcode fixed the implementation for // MARK:
in the editor for ObjC.
目標c# pragma mark—與其他代碼標記機制(如/ ?)不一致。:/ / ! ! !:, //修理我和其他人。在Swift中實現了// MARK:,在ObjC中實現了一半,這一事實在Xcode本身中是不一致的,直到Xcode在ObjC的編輯器中修復了// / MARK:的實現。
With Xcode 8.3
在Xcode 8.3
// MARK: - Line In Sand
works in Objective C properly and no longer shows the "MARK" artifact in the menu.
正確使用Objective - C,不再顯示菜單中的“標記”工件。
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2016/03/21/7212c0724858eab72639fb38b4f29139.html。