9

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.

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 e.g. http://en.cppreference.com/w/cpp/string/basic_string/empty, exactly as it does for objc and Swift.

How is this possible?

Current output just looks like this: enter image description here

stk
  • 6,311
  • 11
  • 42
  • 58

3 Answers3

13

You cannot. According to Apple's Xcode release notes, as of Xcode 8.3

3rd party docset support is now deprecated and will no longer be supported in a future release of Xcode. (30584489)

There are alternate doc browsers, like Dash which allow you to install your own documentation. 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. (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.

christopherdrum
  • 1,513
  • 9
  • 25
  • 4
    This is likely the answer the O.P. is looking for -- Apple really only supports documentation for the languages it "owns" (Objective-C & Swift) and a feature request for other language documentation support should be sent in for Xcode via http://bugreporter.apple.com – Michael Dautermann May 09 '18 at 10:03
5

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 */

enter image description here

Deb S
  • 509
  • 5
  • 16
  • Thanks for your answer! Maybe it could be misunderstood, but I was searching for the code documentation of the C++ code itself, not for custom classes etc. So when I´m clicking on std::string.empty(), it should display the content from e.g. here: en.cppreference.com/w/cpp/string/basic_string/empty – stk May 07 '18 at 13:38
4

I'll upvote Deb's answer but I was also looking at this for a little while.

Markdown in Xcode is somewhat brittle in Xcode 9.

It works for function declarations: Multiline comment

Singleline comment

And also for callouts: Callouts

Documentation comments seems to work well for function declarations, but doesn't work at all for lines of code within the functions.

Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • Thanks for your answer! Maybe it could be misunderstood, but I was searching for the code documentation of the C++ code itself, not for custom classes etc. So when I´m clicking on `std::string.empty()`, it should display the content from e.g. here: http://en.cppreference.com/w/cpp/string/basic_string/empty – stk May 07 '18 at 13:37