简体   繁体   English

如何在Xcode 9.3中显示C ++代码文档?

[英]How can I show C++ code documentation in Xcode 9.3?

I´m developing software based on C++ in Xcode and want to have (at least) the same convenience for code documentation as if I was developing for Swift or objc. 我在Xcode中开发基于C ++的软件,并希望(至少)具有相同的代码文档方便性,就好像我正在为Swift或objc开发一样。

Example: 例:

std::string myString("hello");
if (myString.empty()) {
    // do something
}

If I want to know exactly what .empty() does, I would like to Option-Click on the function and get the documentation overlay with information from eg http://en.cppreference.com/w/cpp/string/basic_string/empty , exactly as it does for objc and Swift. 如果我想确切地知道.empty()作用,我想选择 - 点击该函数并获取文档覆盖,其中包含来自http://en.cppreference.com/w/cpp/string/basic_string/的信息。 ,完全和objc和Swift一样。

How is this possible? 这怎么可能?

Current output just looks like this: 当前输出看起来像这样: 在此输入图像描述

You cannot. 你不能。 According to Apple's Xcode release notes , as of Xcode 8.3 根据Apple的Xcode发行说明 ,截至Xcode 8.3

3rd party docset support is now deprecated and will no longer be supported in a future release of Xcode. 第三方docset支持现已弃用,将来不再支持Xcode。 (30584489) (30584489)

There are alternate doc browsers, like Dash which allow you to install your own documentation. 还有其他文档浏览器,如Dash ,允许您安装自己的文档。 But this does not give you what you're hoping for. 但这并没有给你你所希望的东西。

I have verified that adding a C++.docset into ~/Library/Developer/Shared/Documentation does not work. 我已经验证在~/Library/Developer/Shared/Documentation中添加C ++。docset不起作用。 (likely a directory left over from an earlier Xcode) In fact, removing this directory entirely does not affect Xcode 9.x from correctly displaying the default documentation. (可能是早期Xcode遗留的目录)事实上,完全删除此目录不会影响Xcode 9.x正确显示默认文档。

This is for your custom class. 这适用于您的自定义类。 You can add your comment like this - in the header I do this 您可以像这样添加您的评论 - 在标题中我这样做

 /**
     * Method name: name
     * Description: returns name
     * Parameters: none
     */

here is a sample I did - 这是我做的一个例子 -

#ifndef test_hpp
#define test_hpp

#include <iostream>
#include <string>

class myclass{
private:
    std::string name_;

public:

    myclass(std::string);
    /**
     * Method name: name
     * Description: returns name
     * Parameters: none
     */
    std::string name();
};

#endif /* test_hpp */

在此输入图像描述

I'll upvote Deb's answer but I was also looking at this for a little while. 我会赞成Deb的答案,但我也在考虑这个问题。

Markdown in Xcode is somewhat brittle in Xcode 9. Xcode中的Markdown在 Xcode 9中有些脆弱。

It works for function declarations: 它适用于函数声明: 多行评论

单行评论

And also for callouts: 还有标注: 标注

Documentation comments seems to work well for function declarations, but doesn't work at all for lines of code within the functions. 文档注释似乎适用于函数声明,但对于函数的代码行根本不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM