5

I'm using Doxygen to document API written in Objective-C.
Doyxygen fail to understand NS_ENUM typedef.

I've found this solution but it did not work for me.

ENABLE_PREPROCESSING   = YES 
MACRO_EXPANSION        = YES 
EXPAND_ONLY_PREDEF     = YES 
PREDEFINED             = NS_ENUM(x,y)=y 

Regards, 
  Dimitri 

This is my input file:

/**
 *  Represent the possible states.
 */
typedef NS_ENUM(NSInteger, ABEnumType)
{
    /**
     *  State A.
     */
    StateA = 0,
    /**
     *  State B.
     */
    StateB
};

This is the output I get:

Preprocessing /src/ABEnumType.h...
error: /src/ABEnumType.h:17:17: error: C++ requires a type specifier for all declarations [clang]
error: /src/ABEnumType.h:17:28: error: unknown type name 'ABEnumType' [clang]
error: /src/ABEnumType.h:18:1: error: function definition is not allowed here [clang]
error: /src/ABEnumType.h:17:9: error: C++ requires a type specifier for all declarations [clang]
Parsing file /src/ABEnumType.h...
Ido Ran
  • 10,584
  • 17
  • 80
  • 143
  • Just wondering, have you tried it with a comma after `StateB`? As far as I can tell, that's the only difference between what I have working and your example. – thegrinner May 09 '14 at 18:54
  • @IdoRan almost there. You need to add NS_ENUM(x,y)=enum y – gyurisc Aug 26 '14 at 07:44

3 Answers3

5

The following settings worked for us:

 ENABLE_PREPROCESSING   = YES 
 MACRO_EXPANSION        = YES 
 EXPAND_ONLY_PREDEF     = YES 
 PREDEFINED             = NS_ENUM(x,y)=enum y 

With this we see all the NS_ENUM structures showing up in our doxygen generated documentation

gyurisc
  • 11,234
  • 16
  • 68
  • 102
  • 2
    I had to use a slight variation on this: `PREDEFINED = "NS_ENUM(type, name)=enum name"`. My declarations are in the form: `typedef NS_ENUM(NSInteger, NameOfEnum)` – William Denniss Feb 21 '16 at 08:04
  • More accurately, it should be `PREDEFINED = "NS_ENUM(_type, _name)=enum _name : _type"` – Zhiliang Jan 08 '18 at 09:06
  • It works for me with following configuration. And our enum must be declare inside class or interface <.h> `MACRO_EXPANSION = YES` `PREDEFINED = "NS_ENUM(_type, _name)=enum _name : _type"` – virus May 18 '23 at 17:25
2

If Doxygen fails, you can always try HeaderDocs.

EDIT: I tried headerdocs with a test class and I think it does provide good support of NS_ENUM.

//
//  VLTTestClass.h
//  VPNLoginTest
//

#import <Foundation/Foundation.h>

/*!
 Test class type description.
 */
typedef NS_ENUM(NSInteger, VLTestClassType) {
    /*!
     Description for type 1.
     */
    VLTestClassType1,
    /*!
     Description for type 2.
     */
    VLTestClassType2
};

/*!
 Description for test class
 */
@interface VLTTestClass : NSObject

@end

Here is the headerdoc2html:http://pastebin.com/q6RsR0tU

Athan
  • 777
  • 2
  • 7
  • 21
  • 1
    The funny thing is that HeaderDocs also make a poor job with NS_ENUM. That's why I move to Doxygen :) – Ido Ran Apr 16 '14 at 07:56
  • 1
    @IdoRan The other option is [AppleDoc](http://stackoverflow.com/questions/10109496/objective-c-documentation-generators-headerdoc-vs-doxygen-vs-appledoc). Also a useful plugin for Xcode : https://github.com/onevcat/VVDocumenter-Xcode – Athan Apr 16 '14 at 08:03
  • Hi, thanks. I've found them both. AppleDoc also does not support NS_ENUM :) try that. I've install VVDocumenter it works great. – Ido Ran Apr 16 '14 at 08:10
2

gyurisc's answer helped but we also needed to enable EXTRACT_ALL. So the following settings work for us:

 EXTRACT_ALL            = YES
 ENABLE_PREPROCESSING   = YES 
 MACRO_EXPANSION        = YES 
 EXPAND_ONLY_PREDEF     = YES 
 PREDEFINED             = NS_ENUM(x,y)=enum y
Community
  • 1
  • 1
Jan Deinhard
  • 19,645
  • 24
  • 81
  • 137