Swift Standard Docstrings/ Comments

Does anyone know how to create docstrings in Swift? In the previous version of Xcode, my parameters would show up in the Quick Help as described in this post. Now they no longer do… although, XCode still gives them special highlighting

Can you paste your code for one that isn’t working?

Sure!

/**
 Re-useable struct for each of the tabs.
 
 Making it Identifiable allows it to be used in multiple views differently, versus the same struct changing.
 - parameter view: Matches one of the Tab case statements e.g., Tab.Home, Tab.Feed
 - parameter icon: the name of the icon in the system images (SF Symbols app)
 - parameter name: name for a given tab e.g. home, profile, messages
 */
struct TabInfo: Identifiable {
    // Sets it to a random UUID to conform to the Identifiable protocol
    var id = UUID()
    // represents each view it goes to
    var view: Tab
    var icon: String
    var name: String
}

Generates this:

I’m on Version 13.2.1 (13C100) of Xcode, in v 12, it would work properly. Note below that it at least looks a little different in the docstring for the parameters, I just wish the quick help had the nice formatting too like in the past.

I am also still using Xcode 13.2.1 and your example works fine for me.

Several months back, there was a question about this same issue on Apple’s Developer Forums and what solved it for them was a reboot. (You’ll have to scroll down to see the real answer, apparently the OP in that thread accidentall marked the wrong answer as the solution.)

That looks like it is working as expected. You are adding documentation incorrectly for a struct, which does not have parameters.

What you are trying to add docs to are actually properties of that struct, not parameters, which should be documented themselves, not within the struct.

Parameters would work for function parameters.

/**
 Re-useable struct for each of the tabs.
 
 Making it Identifiable allows it to be used in multiple views differently, versus the same struct changing.
 */
struct TabInfo: Identifiable {
    // Sets it to a random UUID to conform to the Identifiable protocol
    var id = UUID()

    /// Matches one of the Tab case statements e.g., Tab.Home, Tab.Feed
    var view: Tab

    /// the name of the icon in the system images (SF Symbols app)
    var icon: String

    /// name for a given tab e.g. home, profile, messages
    var name: String
}

Ah thanks so much @roosterboy and @mikaelacaron for the second eyes and discussion!!

Good call-out Mikaela!! I thought it took a parameter, and thus should show a parameter in the docs… but of course structs don’t take parameters!!

Appreciate all the help :slight_smile:

1 Like