Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Document methods and enums in Xcode 6 [duplicate]

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 ?

like image 946
NullHypothesis Avatar asked Jul 29 '14 00:07

NullHypothesis


Video Answer


2 Answers

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

like image 91
Milo Avatar answered Oct 06 '22 15:10

Milo


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

like image 31
NullHypothesis Avatar answered Oct 06 '22 13:10

NullHypothesis