【问题标题】:Doxygen fail to detect NS_ENUM in objective-cDoxygen 无法在 Objective-c 中检测到 NS_ENUM
【发布时间】:2014-05-30 21:21:49
【问题描述】:

我正在使用 Doxygen 来记录用 Objective-C 编写的 API。
Doyxygen 无法理解 NS_ENUM typedef。

我找到了这个解决方案,但它对我不起作用。

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

Regards, 
  Dimitri 

这是我的输入文件:

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

这是我得到的输出:

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...

【问题讨论】:

  • 只是想知道,你试过在StateB后面加逗号吗?据我所知,这是我所做的工作与您的示例之间的唯一区别。
  • @IdoRan 差不多了。您需要添加 NS_ENUM(x,y)=enum y

标签: objective-c doxygen nsenumerator


【解决方案1】:

以下设置对我们有用:

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

这样,我们可以看到所有 NS_ENUM 结构都显示在我们的 doxygen 生成的文档中

【讨论】:

  • 我不得不对此稍作改动:PREDEFINED = "NS_ENUM(type, name)=enum name"。我的声明格式为:typedef NS_ENUM(NSInteger, NameOfEnum)
  • 更准确的应该是PREDEFINED = "NS_ENUM(_type, _name)=enum _name : _type"
【解决方案2】:

如果 Doxygen 失败,您可以随时尝试HeaderDocs

编辑:我尝试了带有测试类的 headerdocs,我认为它确实提供了对 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

这里是headerdoc2html:http://pastebin.com/q6RsR0tU

【讨论】:

  • 有趣的是 HeaderDocs 在 NS_ENUM 方面也做得很差。这就是我搬到 Doxygen 的原因 :)
  • @IdoRan 另一个选项是AppleDoc。也是一个有用的 Xcode 插件:github.com/onevcat/VVDocumenter-Xcode
  • 嗨,谢谢。我已经找到了他们两个。 AppleDoc 也不支持 NS_ENUM :) 试试看。我已经安装了 VVDocumenter,效果很好。
【解决方案3】:

gyurisc's 回答有帮助,但我们还需要启用EXTRACT_ALL。所以以下设置对我们有用:

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

【讨论】:

    猜你喜欢
    • 2012-12-14
    • 2012-11-20
    • 2012-10-20
    • 2014-01-15
    • 2011-07-04
    • 2011-06-15
    • 2011-01-03
    • 1970-01-01
    相关资源
    最近更新 更多