Keeping your code tidy with // MARK:
Having an organized codebase should be an essential priority of every software developer. It not only looks good, but will save you (and your colleagues) a lot of time. In Objective-C, the fact that we have an interface file separated from the implementation helps a lot, but we also have the #pragma directive. In Swift however, we have one unified file for your sorce code. While this means that there is half the number of files to navigate in your project, it also means that tidying up and marking the code in that one file is even more important. The way to do it in Swift is to use a special kind of comment - // MARK:. You should use it to separate your code into groups. For example, we want to mark the view life cycle methods:
// MARK: View Lifecycle
Adding a dash (-) in the MARK comment will add a horizontal divider line in the source navigator.
// MARK: -
You can also combine a dash with some text after it to get both line and a label.
// MARK: - UITableViewDelegate
Other Special Comments
Two other comments that will help you mark your code are // TODO: and // FIXME:. As you might guess, their purpose is not to organize the code, but to leave notes to your future self.
The larger your source code files get, the more you need to make sure they are well-organized. Grouping and marking your code will save you time and focus in the long run and it should become a habit.
Happy marking!