Cerniuk
Cerniuk

Reputation: 15190

In Xcode, How do I Suppress "MARK:" part of menu addition?

In Objective C, when using

// MARK: Line In Sand

The default project will produce a menu items with the word "MARK:" in it, or in other words:

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?

Mark not in menu!

Upvotes: 2

Views: 353

Answers (4)

Cerniuk
Cerniuk

Reputation: 15190

Xcode 10 now handles the Objective C and Swift use of

// MARK: - Line In Sand

identically so this question and answer have finally been rendered moot by an Apple update.

(fate of original answer below left to community)

It turns out that the pre-processor in Swift makes special allowance for the

// 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.

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:

// 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

Upvotes: 0

Cerniuk
Cerniuk

Reputation: 15190

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.

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.

With Xcode 8.3

// MARK: - Line In Sand

works in Objective C properly and no longer shows the "MARK" artifact in the menu.

Upvotes: 0

JAL
JAL

Reputation: 42449

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

#pragma mark - Hack

// MARK: HACK

This will appear like so:

mark

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

// MARK: Something

Swift mark

Upvotes: 2

mfessenden
mfessenden

Reputation: 608

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

#pragma mark Line In Sand

Upvotes: 0

Related Questions