How to replace #pragma mark in Swift for code organization?
Hi everyone! I'm switching from Objective-C to Swift and encountered a problem with code organization. In Objective-C, I actively used the `#pragma mark` directive to separate methods into logical groups in Xcode's navigation bar. For example:
```objc
#pragma mark - Lifecycle
- (void)viewDidLoad { ... }
- (void)viewWillAppear:(BOOL)animated { ... }
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { ... }
```
This helped quickly navigate large files. In Swift, I tried to write `#pragma mark - Lifecycle` but got a compilation error: "Use of unresolved identifier 'pragma'". I googled it and found out that Swift doesn't have `#pragma mark`. So how do you structure code? Currently, my file looks like a mess of methods.
No answers yet.
Log in to leave an answer