6

I have an enumeration in Swift:

 enum DateFormat{
   case ShortDateFormat //7/28/2014 ShortStyle
   case LongDateFormat  //July 28, 2014 LongStyle
   case LongFormatWithDay //Monday, July 28, 2014 FullStyle
   case CurrentDayThreeLetters //Mon
 }

And I'd like to have this documented similar to how intellisense works in C#, where the moment I type DateFormat.ShortDateFormat, the popup will tell me that this produces 7/28/2014.

I'd also like to do this with hard-to-remember functions I wrote that return specific things to make it easier on me so I don't have to go back to the file and look up exactly what it did (not that I have many of those functions, mind you) !

How could I do such a thing ?

Jeremy J Starcher
  • 23,369
  • 6
  • 54
  • 74
NullHypothesis
  • 4,286
  • 6
  • 37
  • 79
  • 1
    [HeaderDoc tags](https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/HeaderDoc/tags/tags.html) work in Obj-C code, but I'm not sure if they work for Swift yet. – jtbandes Jul 29 '14 at 00:21
  • Apparently all you have to do is add triple slashes (///) to do this! awesome! – NullHypothesis Jul 29 '14 at 01:00

2 Answers2

7

HeaderDoc tags work in Objective-C and Swift although in Swift, the format is a little different. In Objective - C, the proper format to document a method was this:

/*!
 * @discussion This is an example discussion.
 * @param bar - This is an example of a parameter.
 * @return An example for a return type
 */
-(id)foo:(bar)foobar;

The result when alt-clicking foo: is this

image1

In swift, the way to document is a little different:

/**
This is an example discussion

:param: bar This is an example parameter.

:returns: This is an example return type.
*/

func foo(foobar: AnyObject) -> AnyObject {...}

This gives the same example when alt-clicking as above.

For an enum, its the same principle as above using the /** */ format but also uses /// for individual enum descriptions as well.

/**
Example enum description

- First: First example
- Second: Second example
- Third: Third example
- Fourth: Fourth example
*/
enum Example {
    ///First example
    case First
    ///Second example
    case Second
    ///Third example
    case Third
    ///Fourth example
    case Fourth
}

The result is a neatly formatted, bulleted list: image2

And when alt-clicking one of the actual cases: image 3.

You will get your desired effect using the autocomplete as shown below: image4

Milo
  • 5,041
  • 7
  • 33
  • 59
1

To do this, you simply need to add triple forward slashes (///) to do this and it will work.

/// My Comment Here to Appear In "Intellisense" Popup

NullHypothesis
  • 4,286
  • 6
  • 37
  • 79