How to easy document your swift code with Jazzy

This is quick and very basic guide on how to install and use awesome open-source project called Jazzy that may help you to create html, Apple-style like documentation for your code.

Before even proceeding to installation make sure you document your code appropriate, for example:

    /**
     Function to get formatted time
     
     - parameter interval: NSTimeInterval value
     
     - returns: NSString of formatted time
    */
    func stringFromTimeInterval(interval:NSTimeInterval) -> NSString {
        let ti = NSInteger(interval)
        let ms = Int((interval % 1) * 1000)
        let seconds = ti % 60
        let minutes = (ti / 60) % 60
        let hours = (ti / 3600)
        return NSString(format: "%0.2d:%0.2d:%0.2d.%0.3d",hours,minutes,seconds,ms)
    }

So, if you have done a good job of documenting your code you probably thinking on how to export all your commenting into HTML pages?

Well, there is very simple way:

  1. Open terminal (cmnd+space)
  2. Run next command: sudo gem install jazzy
  3. Enter your user password and wait till it's done installing files
  4. Navigate to your project folder, with command cd, for example: cd [your-folder]/ [sub-folder]/ [your-project-folder]
  5. Run command: jazzy
  6. Profit!

By default jazzy only documents public declarations. So, if running just jazzy command does not produce any meaningful documentation, expand it with next:

jazzy --min-acl internal
or
jazzy --min-acl private

Produced html pages can be found in your project /docs folder and will look something like this:

jazzy_documentation_example

Hope this basic step-by-step helps!

Sources:

Swift Documentation

Jazzy

947 total views, 1 views today

Leave a Reply

Your email address will not be published. Required fields are marked *