在Xcode中,如何抑制菜單添加的“MARK:”?

[英]In Xcode, How do I Suppress “MARK:” part of menu addition?


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:”字樣的菜單項,或者換句話說:

Line In Sand showing 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注釋風格時,沙中的線只顯示“沙中的線”(沒有“標記”)。他們怎么做到的?這僅僅是一個基本的改進嗎?

Mark not in menu!

5 个解决方案

#1


2  

In Objective-C, you can make a mark like that in two different ways:

在Objective-C中,你可以用兩種不同的方式做這樣的標記:

#pragma mark - Hack

// MARK: HACK

This will appear like so:

這看起來是這樣的:

mark

In Swift, you only get // MARK, which is treated like a pragma mark.

在Swift中,您只能得到//標記,這被視為實用標記。

// MARK: Something

Swift mark

#2


0  

If you're in Objective-C, use this syntax:

如果你在Objective-C中,使用以下語法:

#pragma mark Line In Sand

#3


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.

不僅生成分隔行,還生成“無標記”菜單項……但是只有在斯威夫特。

Swift preprocessor cleans up 'MARK' where as ObjC does not

#4


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"

壓制“標記”,你只能得到分隔符和“沙線”

#5


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



 
粤ICP备14056181号  © 2014-2021 ITdaan.com