{"id":22,"date":"2012-12-09T11:37:00","date_gmt":"2012-12-09T11:37:00","guid":{"rendered":"https:\/\/geeknation.de\/?p=22"},"modified":"2025-07-23T17:18:01","modified_gmt":"2025-07-23T15:18:01","slug":"201212doxygen-in-xcode-4","status":"publish","type":"post","link":"https:\/\/geeknation.de\/?p=22","title":{"rendered":"Doxygen in Xcode 4"},"content":{"rendered":"<p>If you develop your software in groups, create a framework, or just want to show your latest development project to other people, your want documentation for your code. For Objective-C in Xcode projects there are solutions like <a href=\"http:\/\/developer.apple.com\/opensource\/tools\/headerdoc.html\">HeaderDoc<\/a>&nbsp;or <a href=\"http:\/\/www.cocoadev.com\/index.pl?AutoDoc\">AutoDoc<\/a>, but the lack of solid documentation seems almost ironic. So I found <a href=\"http:\/\/www.stack.nl\/~dimitri\/doxygen\/\">doxygen<\/a>, which has better documentation and supports multiple platforms, multiple programming languages, and multiple output formats.<br \/>\nNow, how do you generate the documentation automatically via Xcode? Here are the easy steps:<\/p>\n<h2>1. Format your header files for doxygen<\/h2>\n<p>To tell doxygen about your source code, you must add comments in your header files. The official description can be found <a href=\"http:\/\/www.stack.nl\/~dimitri\/doxygen\/docblocks.html\">here<\/a>, but I will show you some basics:<\/p>\n<\/p>\n<blockquote><\/blockquote>\n<\/p>\n<pre class=\"source-code\">#import &lt;Foundation\/Foundation.h&gt;<br><br>\/**<br> * A utility class for the project.<br> * Provides useful methods for the other classes.<br> *<br> * @author Oliver Eichhorn<br> *\/<br><br>@interface Util : NSObject<br><br>\/\/\/ An array containing DetailPeopleSection objects.<br>@property (nonatomic, strong) NSMutableArray *sections;<br><br>\/**<br> * Gets all the InfoContent strings with the given ID<br> * from the given array.<br> *<br> * @param iid      the iid of the InfoContent object<br> *                 in the infoContentArray<br> * @param icArray  the array of InfoContent objects<br> *                 to be searched<br> *<br> * @return an array with found InfoContent strings<br> *\/<br>+(NSMutableArray*)getInfoContentStringsById:(int)iid<br>                  fromArray:(NSArray*)infoContentArray;<br>@end<\/pre>\n<p>In this example, you can see how to comment a class, a property, and a method. If you have used JavaDoc before, you will feel right at home.<\/p>\n<\/p>\n<h2>2. Getting and setting up doxygen<\/h2>\n<p>You can download the lastest version&nbsp;<a href=\"http:\/\/www.stack.nl\/~dimitri\/doxygen\/download.html#latestsrc\">here<\/a>. The Mac version has a nice GUI which you can see in the screenshot.<\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/geeknation.de\/wp-content\/uploads\/2013\/07\/doxygen.png\" \/><\/p>\n<p>With this tool we can do two things: Generate the doxygen config file, and generate the documentation files for your source code.<\/p>\n<p>First you should set the three paths: The &#8220;working directory&#8221; is the path where the doxygen config file will be generated. The &#8220;source code directory&#8221; is the path where your source code lies. Finally, the &#8220;destination directory&#8221; is the path where the documentation files will be generated. Separate directory for each format (e. g. &#8220;html&#8221;) will be generated here.<\/p>\n<p>Furthermore you can configure the projects name, synopsis, and version.<\/p>\n<p>In the topics &#8220;Mode&#8221;, &#8220;Output&#8221;, and &#8220;Diagrams&#8221; you can change more basic settings. In the &#8220;Expert&#8221; tab you can go crazy and configure every little detail of doxygen.<\/p>\n<p>You can force doxygen to handle your source files as Objective-C files with EXTENSION_MAPPING in the &#8220;Expert&#8221; tab. Just enter the two entries &#8220;m=Objective-C&#8221; and &#8220;h=Objective-C&#8221;. I didn&#8217;t see differences in the resulting documentation, though.<\/p>\n<p>If you are finished with the settings, you should save the config file in the &#8220;File&#8221; menu.<\/p>\n<p>You could now go the the next step, but if you cannot wait to see the generated documentation, select the &#8220;Run&#8221; tab and click on &#8220;Run doxygen&#8221;. The documentation files will be generated in the destination directory.<\/p>\n<h2>3. Automatically call doxygen from Xcode<\/h2>\n<p>You could call the doxygen GUI every time you change the source code, but you don&#8217;t want to do that. In Xcode, there is an easy way to add doxygen to you build process:<\/p>\n<p>In Xcode, select you project in the project navigator and select a target under &#8220;TARGETS&#8221;.&nbsp;Click on &#8220;Build Phases&#8221; and on the lower part of the screen select &#8220;Add Build Phase \/ Add Run Script&#8221;.<\/p>\n<p>In the script field enter the following two lines:<\/p>\n<pre class=\"source-code\">\/Applications\/Doxygen.app\/Contents\/Resources\/doxygen \"$SOURCE_ROOT\/Doxyfile\"<br>exit 0<br><\/pre>\n<p>The string &#8220;\/Applications\/Doxygen.app\/Contents\/Resources\/doxygen&#8221; is the doxygen command line tool, which is contained in the bundle of the doxygen GUI. If the GUI is installed at a different place, adjust accordingly.<\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/geeknation.de\/wp-content\/uploads\/2013\/07\/xcode.png\" \/><\/p>\n<p>The string &#8220;$SOURCE_ROOT\/Doxyfile&#8221; is the doxygen config file which we generated before in section 2. The environment variable SOURCE_ROOT is the root directory of your project. If your config file lies at a different directory, please adjust accordingly. You can also enter the absolute path. If there is a space in the path, you must use quotation marks like I did it in the example.<\/p>\n<h2>4. Generate the documentation<\/h2>\n<p>Now, every time your project is built in Xcode, the documentation files are generated or updated. Isn&#8217;t that nice?<\/p>\n<h3>Used sources:<\/h3>\n<ul>\n<li>Duck Rowing:&nbsp;<a href=\"http:\/\/www.duckrowing.com\/2010\/03\/18\/documenting-objective-c-with-doxygen-part-i\/\">Documenting Objective-C with Doxygen Part I<\/a><\/li>\n<li>iphonepills:&nbsp;<a href=\"http:\/\/iphonepills.wordpress.com\/2011\/08\/18\/tutorial-xcode-4-0-doxygen\/\">Tutorial XCode 4.0 Doxygen<\/a><\/li>\n<li>Doxygen:&nbsp;<a href=\"http:\/\/www.stack.nl\/~dimitri\/doxygen\/index.html\">Doxygen manual<\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you develop your software in groups, create a framework, or just want to show your latest development project to other people, your want documentation for your code. For Objective-C in Xcode projects there are solutions like HeaderDoc&nbsp;or AutoDoc, but the lack of solid documentation seems almost ironic. So I found doxygen, which has better [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,6],"tags":[],"class_list":["post-22","post","type-post","status-publish","format-standard","hentry","category-programmierung","category-technik"],"_links":{"self":[{"href":"https:\/\/geeknation.de\/index.php?rest_route=\/wp\/v2\/posts\/22","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/geeknation.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/geeknation.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/geeknation.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/geeknation.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=22"}],"version-history":[{"count":2,"href":"https:\/\/geeknation.de\/index.php?rest_route=\/wp\/v2\/posts\/22\/revisions"}],"predecessor-version":[{"id":427,"href":"https:\/\/geeknation.de\/index.php?rest_route=\/wp\/v2\/posts\/22\/revisions\/427"}],"wp:attachment":[{"href":"https:\/\/geeknation.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=22"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/geeknation.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=22"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/geeknation.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=22"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}