40

I am adding some description to my method in class. This is how I achieved this:

enter image description here

And it looks like this upon clicking...

enter image description here

How can I make the underlined method clickable? I want it to be referenced so that when a user clicks on it, they are directed to a particular web page for documentation.

Is it even possible? Thanks in advance, any help will be appreciated

Akshansh Thakur
  • 5,163
  • 2
  • 21
  • 38

3 Answers3

115

New in Xcode 13

Using the new DocC tool in Xcode, you can now reference other methods by using a double backtick.

If the type, property, or method you are referencing is not a "sibling" of the one you are documenting, you can refer to it by qualifying the reference.

struct House {
    /// The rooms in the house.
    var rooms: [Room]

    /// The maximum size of the household.
    ///
    /// This is calculated by summing the ``Room/occupancyLimit`` of this 
    /// house's ``rooms``.
    var maximumHouseholdSize: ...
}

struct Room {
    /// The maximum number of occupants allowed in the room.
    var occupancyLimit: ...
}

Here, the documentation comment for House.maximumHouseholdSize references House.rooms with:

``rooms``

because rooms is a sibling of maximumHouseholdSize.

It also references Room.occupancyLimit with:

``Room/occupancyLimit``

because occupancyLimit is not nested in the same type, but rather under the Room type.


Prior to Xcode 13

You can link to another method by tagging it with /// - Tag: and referring to it by Tag using the x-source-tag://[Tag] scheme like so:

/// - Tag: someMethod
func someMethod() {
   ...
}

/// Make sure to call [someMethod](x-source-tag://someMethod) at some point when overriding.
func otherMethod() {
   ...
}

Clicking on the someMethod link in the Quick Help pop-over will take you to the method and flash-highlight it in yellow.

Clay Ellis
  • 4,960
  • 2
  • 37
  • 45
  • 1
    Sorry, I just re-read the question and realized that the OP was asking about linking to web pages. This is an answer to the title of the question, though, so I'm leaving it in place. – Clay Ellis Feb 06 '19 at 23:51
  • Does not seem to work in Playgrounds with Xcode 10.2.1 – Kentzo Jun 09 '19 at 18:39
  • 2
    THIS IS AMAZING!! I've been looking for this for 3 years now! Works in Xcode 11.5 as well. Thank you! – Sajjon Jun 16 '20 at 06:40
  • This works well, but overrides any other comments that you may have below it. – aheze Oct 26 '20 at 16:05
  • about "x-source-tag", what if I have 2 files, each have a tag of the same name. Can Xcode figure out which one to link to? – Goatt Jan 30 '22 at 22:11
  • How to link to a particular line number? – abc123 Jun 21 '22 at 15:49
-1

This link solved my problem

Particularly, this is how I went about it

enter image description here

Thanks to Oleg for the link

Akshansh Thakur
  • 5,163
  • 2
  • 21
  • 38
  • 3
    using (as the image suggests) `https://www,myLink` doesn't work for me. I would have been very surprised if it did have worked, but I checked it anyhow. I'm using Xcode 9.4 – Michael Jun 09 '18 at 13:03
  • 1
    I really tried to find solution for this problem. Unfortunately, it seems the JavaDoc style links are still unsupported even in Xcode 10. Sad... – Stan Mots Aug 06 '18 at 12:54
-3

Use this

 /**
     *  <#Description#>
     *
     *  @link UILabel <#UILabel description#>
     *
     *  @return <#return value description#>
     */

Or you can try vvDocumenter for giving comments

Vibha Singh
  • 623
  • 4
  • 9
  • 2
    I don't think that works. I just tried this syntax: `<#ClassName methodName#>` and I think that's the syntax for autocomplete suggestion placeholders. – Apoorv Khatreja Nov 21 '17 at 20:39