Author Topic: How to Organize Your Code with Comment Tags in Swift  (Read 5131 times)


  • Administrator
  • *****
  • Posts: 719
    • View Profile
How to Organize Your Code with Comment Tags in Swift
« on: July 01, 2015, 03:12:35 PM »
Xcode provides three options for organizing your code with the MARK, TODO, and FIXME comment tags.

Swift’s MARK comment tag is the most commonly used. First, you must physically group related methods together in your source code file. Next, add the following directive in your code file before each group of methods, where Group Name is a name you enter describing the type of methods in that group:

Code: [Select]
// MARK: - Group Name
For example, you can create a group called Calculator User Interface like this:

Code: [Select]
// MARK: - Calculator Core Logic
This displays a group in the jump bar member list:

The TODO and FIXME comment tags allow you to mark your code that needs further attention. For example, check out these FIXME and TODO comment tags:

Code: [Select]
class ScientificCalculator : Calculator {
    var memory: Double = 0.0
    // FIXME: Clear all memory properties
    override func clear() {
        self.memory = 0.0
    // TODO: Implement square root

This adds the tags to the method drop down box:

Note that adding a hyphen to the MARK tag adds a separator to the method list, but adding a hyphen to TODO and FIXME does not.

All the best!
Kevin McNeish
Author of Learn to Code in Swift:
Check out our Robot Tic-Tac-Toe app:
« Last Edit: November 14, 2015, 01:25:26 PM by kjmcneish »