Xcode provides an easy way to generate documentation. To use this feature, click on any class, property, function, or part you want to add a document. Then press ⌥ – Option + ⌘ - command + / or Editor > Structure > Add documentation from Xcode's menu. Xcode will generate a document template for you.
You can also access Developer Documentation window from the Xcode Help menu. Another option is by using the keyboard shortcut Command+Shift+0.
The Xcode 12.5. 1 release supports on-device debugging for iOS 9 and later, tvOS 9 and later, and watchOS 2 and later. Xcode 12.5. 1 requires a Mac running macOS Big Sur 11 or later.
Xcode 13 requires a Mac running macOS 11.3 or later.
Here is an example of all the options I have found as of Xcode 5.0.2
That was generated with this code:
/** First line text.
Putting \\n doesn't create a new line.\n One way to create a newline is by making sure nothing is on that line. Not even a single space character!
@a Italic text @em with @@a or @@em.
@b Bold text with @@b.
@p Typewritter font @c with @@p or @@c.
Backslashes and must be escaped: C:\\foo.
And so do @@ signs: user@@example.com
Some more text.
@brief brief text
@attention attention text
@author author text
@bug bug text
@copyright copyright text
@date date text
@invariant invariant text
@note note text
@post post text
@pre pre text
@remarks remarks text
@sa sa text
@see see text
@since since text
@todo todo text
@version version text
@warning warning text
@result result text
@return return text
@returns returns text
@code
// code text
while (someCondition) {
NSLog(@"Hello");
doSomething();
}@endcode
Last line text.
@param param param text
@tparam tparam tparam text
*/
- (void)myMethod {}
Notes:
/** block */
, /*! block */
, or prefixed with ///
or //!
.@
(headerdoc style) or the \
(doxygen style) prefix. (I.e. @b
and \b
both do the same thing.)@property
text.) They can come afterwards, on the same line, with /*!<
, /**<
, //!<
, ///<
.@returns
.This will show the brief text (with no formatting); if no brief text exists, it will show a concatenation of all the text up to the first @block; if none exists (e.g. you begin with @return), then it will concat all the text striping away all @commands.
(See first screenshot.)
Since the commands in Xcode 5 are compatible with Doxygen, you could download and use Doxygen to generate documentation files.
For a general introduction to Doxygen and how to document Objective-C code, this page seems like a good resource.
Descriptions of some of the supported commands:
@brief
: will insert text at the beginning of the description field, and is the only text that will appear during code completion.The following don't work:
\n
: doesn't generate a newline. One way to create a newline is by making sure nothing is on that line. Not even a single space character!\example
The following are not supported (they don't even appear in dark green):
Apple uses what appears to be reserved keywords that only works in their documentation. Although they appear in dark green, it looks like we cannot use them as Apple does. You can see examples of Apple's usage in files such as AVCaptureOutput.h.
Here is a list of some of those keywords:
At best, the keyword will cause a new line in the Description field (e.g. @discussion). At worst, the keyword and any text following it will not appear in the quick help (e.g. @class).
Swift 2.0 uses the following syntax:
/**
Squares a number.
- parameter parameterName: number The number to square.
- returns: The number squared.
*/
Notice how @param
is now - parameter
.
You can also now include bullets in your documentation:
/**
- square(5) = 25
- square(10) = 100
*/
Senseful:
You may need to build your project before the latest changes to your documentation appear.
Sometimes this hasn't been enough for me. Closing Xcode and opening the project back up usually remedies those cases.
I'm also getting different results in .h files and .m files. I can't get new lines when the documentation comments are in a header file.
Most of the formatting has changed for Swift 2.0 (as of Xcode7 ß3, also true in ß4)
instead of :param: thing description of thing
(as it was in Swift 1.2)
it is now - parameter thing: description of thing
Most of the keywords have been replaced by - [keyword]: [description]
instead of :[keyword]: [description]
. Currently the list of keywords that don't work includes, abstract
, discussion
, brief
, pre
, post
, sa
, see
, availability
, class
, deprecated
, method
, property
, protocol
, related
, ref
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With