Can DocC Generate Documentation for Extensions?

Is there a way to force the documentation compiler to generate documentation for extensions to types outside a package/framework?

This is incredibly important, as some packages and frameworks extend types that are part of the Swift Foundation (e.g., extensions to primitive types and collection) and SwiftUI (e.g., view modifiers and environment values).

Answered by DTS Engineer in 709776022

DocC still doesn't generate documentation for the extensions.

If you want to get involved in the effort to fix this, I recommend that you bounce on over to Swift Forums > DocC. I think that this is the most relevant thread.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I have the same question too.

The solution is to use inside a package a public protocol with a type constraint and declare the type to conform to the protocol. Now you get the documentation you want.

It is a cleaner solution than just using an extension.

Example:

import Foundation

// The extension:
public protocol FileManagerExtension: FileManager { }
extension FileManager: FileManagerExtension { } // I don't know why this doesn't have to be public!

// The new function:
public extension FileManagerExtension {
    /// My new function.
    /// - Returns: 42.
    func myNewFuntion() -> Int { return 42 }
}

I tried Nankea's solution, but it doesn't work for SwiftUI's View:

public protocol ViewExtension: View { }
extension View: ViewExtension { } // I don't know why this doesn't have to be public!

public extension ViewExtension {
    /// Places an alphabetical index next to the view.
    /// - Parameter style: A style to apply to the index.
    /// - Returns: The view with the added index.
    public func alphabeticalIndex(style: AlphabeticalIndexStyle = AlphabeticalIndexStyle.default) -> some View {
        self.modifier(AlphabeticalIndex(style: style))
    }
}

I get "Extension of protocol 'View' cannot have an inheritance clause" on the second line.

This REALLY needs to be fixed!

Nankea, while you have a good point regarding the extension of unowned types, DocC still doesn't generate documentation for the extensions.

DocC still doesn't generate documentation for the extensions.

If you want to get involved in the effort to fix this, I recommend that you bounce on over to Swift Forums > DocC. I think that this is the most relevant thread.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Can DocC Generate Documentation for Extensions?
 
 
Q