Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Swift APIView] Decide how to handle protocol adoption #3089

Closed
tjprescott opened this issue Apr 6, 2022 · 0 comments · Fixed by #4789
Closed

[Swift APIView] Decide how to handle protocol adoption #3089

tjprescott opened this issue Apr 6, 2022 · 0 comments · Fixed by #4789
Assignees
Labels
APIView Priority 3 APIView Client This issue points to a problem in the data-plane of the library. Swift

Comments

@tjprescott
Copy link
Member

tjprescott commented Apr 6, 2022

Related to: #2536

Here's a textbook example of protocol adoption from Apple's docs:

// Some public protocol
public protocol TextRepresentable {
    var textualDescription: String { get }
}

// Some struct that implements that protocol but doesn't declare it
public struct Hamster {
    public var name: String
    public var textualDescription: String {
        return "A hamster named \(name)"
    }
}

// Protocol adoption
public extension Hamster: TextRepresentable {}

APIView will completely ignore the extension because it doesn't contain anything public. However, this line is very important for the public API because it means that Hamster can be used anywhere TextRepresentable is accepted, but the APIView won't show that.

Option 1
Render the extension within the Hamster definition, even though this is not accurate Swift syntax.

public struct Hamster {
    public var name: String
    public var textualDescription: String {
        return "A hamster named \(name)"
    }
}

public extension Hamster: TextRepresentable {}

Option 2
Interpret the declaration and modify the struct definition, thus affecting how it is rendered:

// By interpreting the protocol adoption, we add it to the inheritance list here.
public struct Hamster: TextRepresentable {
    public var name: String
    public var textualDescription: String {
        return "A hamster named \(name)"
    }
}
@tjprescott tjprescott added APIView Client This issue points to a problem in the data-plane of the library. APIView Priority 3 Swift labels Apr 6, 2022
@tjprescott tjprescott self-assigned this Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
APIView Priority 3 APIView Client This issue points to a problem in the data-plane of the library. Swift
Projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

1 participant