#pragma mark is a navigation hint for Xcode’s jump bar — it generates no code and has zero effect on your app. Use #pragma mark - Name in Objective-C to group methods, and // MARK: - Name in Swift, where #pragma does not exist.Why this happens
#pragma mark looks like it should do something at runtime, but it does not. It is a compiler directive that Clang recognises and then discards: no code is generated, no symbol is emitted, nothing changes in the binary. Its only real consumer is the Xcode editor.
The confusion comes from two places. First, #pragma in C and Objective-C is a general escape hatch for compiler-specific instructions such as #pragma once or #pragma clang diagnostic, so it is natural to assume mark is another one of those. Second, the directive sits between method implementations, which makes it look like part of the program structure rather than metadata for the IDE.
The C standard says a compiler that does not recognise a pragma may ignore it — which is exactly what happens here. A mark is effectively a comment written in a syntax Xcode happens to parse.
How to fix it
1. Use #pragma mark to label groups of methods in Objective-C
Put the directive directly above the group it describes, inside the @implementation block:
@implementation CheckoutViewController
#pragma mark - Lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.items.count;
}
#pragma mark - Actions
- (IBAction)payTapped:(id)sender {
// ...
}
@end
The three forms behave slightly differently:
#pragma mark -draws a separator line with no title.#pragma mark - Lifecycledraws the separator plus the titleLifecycle.#pragma mark Lifecycleshows the title without the separator line.
Once the marks are in place, Xcode lists them in the jump bar at the top of the editor (click the last breadcrumb item to drop the menu down), in the symbol navigator, and in the minimap. That is the entire benefit: faster navigation in a long file.
2. Place the mark above the right method
A mark labels everything from that line down to the next mark or the end of the enclosing block. Put it one method too high and the whole rest of the file is mislabelled in the jump bar. This is the only sense in which location matters.
There is no required ordering and no rule that some pragmas must come first. Marks are legal anywhere a declaration or statement is legal: between methods inside @implementation, above @interface in a header, and in plain .c or .mm files. A convention that works well:
- File-scope sections first (
Lifecycle,Public API). - Protocol conformances next (
UITableViewDataSource,UITableViewDelegate). - Private helpers and actions last.
3. In Swift, use // MARK: instead
#pragma mark is not valid Swift. Swift has no #pragma directive at all, so the compiler will reject it. The equivalent is a comment that Xcode’s parser understands:
struct CheckoutView: View {
// MARK: - State
@State private var items: [Item] = []
// MARK: - Body
var body: some View {
List(items) { item in
Text(item.title)
}
}
// MARK: - Actions
private func pay() {
// ...
}
}
The spelling matters: // MARK: must be uppercase and must include the colon. // MARK: - produces the separator, // MARK: Name produces a title. Xcode also picks up // TODO: and // FIXME: and lists them in the jump bar alongside your marks, which is a cheap way to surface unfinished work.
4. Split the file when marks stop being enough
Marks are a navigation aid, not a structuring tool. If a file needs more than a handful of them, the file is doing too much. In Objective-C, move protocol conformances into categories or class extensions in their own files. In Swift, use separate extension blocks — or separate files — per conformance. The jump bar then reflects real structure instead of labels you have to maintain by hand.
5. Removing a mark is harmless
Deleting a #pragma mark or // MARK: breaks nothing: no build error, no runtime change, no behaviour difference. You would remove one when the file is being split up, when the group it labelled no longer exists, or when the label has drifted away from the methods underneath it. The only cost is losing the entry in the jump bar.
How to prevent it
- Treat marks as documentation: move or rename them whenever you move the methods beneath them.
- Pick one convention per language and keep it —
#pragma mark - Namein Objective-C,// MARK: - Namein Swift. - Never rely on a mark for conditional compilation or any build-time behaviour; it does nothing.
- Keep marks out of headers unless the header is genuinely long enough to need them.
- If you are scrolling to find a method more than once a day, split the file instead of adding another mark.
FAQ
Does #pragma mark change the compiled binary?
No. It produces no instructions and no symbols. Two builds of the same source, one with all marks stripped, are functionally identical.
Why doesn’t #pragma mark work in Swift?
Swift has no #pragma directive, so the compiler has nothing to interpret. Use // MARK: - Name instead; Xcode treats it the same way in the jump bar.
Do I have to add #pragma mark to every file?
No. It is entirely optional and purely cosmetic. Short files read fine without any marks, and adding them to a 60-line class just adds noise.
Parts of this guide are adapted from content licensed under CC BY-SA 4.0; this article is shared under the same license.