Adding Descriptions to the Documentation
It's nice to have a list of all our methods, but to really help our team we will have to write some good descriptions that will let them figure out how to use the methods. There are many different ways to do this with Doxygen, and you can find them in the Doxygen manual. These steps will get you started.
Let's start by editing DemoView.h. Open this file in the Xcode editor. It's often good to focus our documentation efforts on the header, as it describes the public interface to the class.
Notice that DemoView.h has two block comments at the beginning of the file. Let's modify the comments so that they show up in the class documentation. Add an extra asterisk (
*) to the opening of the comment. The first line will be:
Now remove the comment closer (
*/) from the first comment and the comment opener (
/*) from the second comment so that all of the comment text at the beginning of the file is contained within one comment.
Because our comment uses the double-asterisk opener and is at the top of the DemoView.h file, the contents of the comment will be used as the description for the DemoView class.
Build your project (press Cmd-B), and view the class documentation for DemoView to see the changes.
Let's add some more comments. Go back to the DemoView.h file and add the following line above the
/** Stores the type of shape to draw. 0=rectangles, 1=circles,2=bezierPaths, 3=circle clipping */
Because the comment starts with the double asterisk and is directly before the
numdeclaration, this comment will be attached to the
numvariable in the documentation.
setDemoNumbermethod declaration, add the following comment:
/** Called by the interface to set the num variable @param newNum an integer specifying the kind of shape to draw. 0=rectangles, 1=circles, 2=bezierPaths, 3=circle clipping */
Because this comment is directly above the
setDemoNumberfunction declaration, it will describe this function in the documentation. Also, notice that we were also able to describe a parameter by using the
Build your project, and check out the documentation changes.
Before we conclude, I want to show you one more way of adding comments to the code. It often creates cleaner-looking code when a comment is on the same line as a variable declaration. For example, open the PathDemoController.h file in Xcode and find the following lines:
NSButton *button; NSPopUpButton *popup; NSWindow *window; DemoView *demoView;
Change those lines of code to the following:
NSButton *button; /**< "Run Again" button in GUI */ NSPopUpButton *popup; /**< "Choose a path demo" popup in GUI */ NSWindow *window; /**< GUI window */ DemoView *demoView; /**< Custom view for displaying shapes */
By adding the
> to the opening of the comment, we can use a comment that comes directly after the code that it refers to instead of placing the comment on the line above it. The documentation for Doxygen (or whatever document tool you choose to use) will have many little tricks like that, so be sure to check it out.
Automated API documentation for your code is easy to set up and even easier to maintain. Xcode can handle a lot of the repetitive work so that all you need to do is furnish some short descriptive comments as you maintain your code. Spend an hour or two evaluating the different documentation tools out there that work with your language of choice, and talk to your team about creating a policy for documenting code that way.
Something cool to consider is that because the documentation is integrated into the code, it works very well with a source control system such as CVS. If you check in your code for a daily build, that build could update the documentation on an intranet for all the developers. I'm interested (and I'm sure others are too) in learning how people are using automated code documentation in their real-world projects. I encourage you to leave a comment letting us know what your favorite documentation tools are and how you integrate them into your build system.
Return to MacDevCenter.com.
Viewing documentation in Xcode
2004-09-21 09:16:05 flit [View]
2004-09-15 08:49:40 cparnot [View]
2004-08-30 11:21:41 i_iwas [View]
2004-08-30 03:55:01 znek [View]
2004-08-28 12:30:31 BernhardGruber [View]