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

ConnectError.unpackedDetails Swift 6 Compatibility #323

Closed
eseay opened this issue Nov 26, 2024 · 0 comments · Fixed by #324
Closed

ConnectError.unpackedDetails Swift 6 Compatibility #323

eseay opened this issue Nov 26, 2024 · 0 comments · Fixed by #324

Comments

@eseay
Copy link
Contributor

eseay commented Nov 26, 2024

I have a helper extension in one up my packages that depends on Connect-Swift that is defined as follows:

func unpackFirst<M: SwiftProtobuf.Message>(_ messageType: M.Type) -> M? {
    unpackedDetails().first
}

...which is used in a manner similar to what's described in the doc comment for ConnectError.unpackedDetails:

let myMessage = error.unpackFirst(SomeMessageType.self).

I am working on migrating my package to support Swift 6, and when building with Xcode 16.1 and compiling with Swift 6, I am receiving the following error in my function's implementation

unpackedDetails().first -> "Type of expression is ambiguous without a type annotation".

I have been able to resolve the issue by adjusting my function implementation as follows:

func unpackFirst<M: SwiftProtobuf.Message>(_ messageType: M.Type) -> M? {
#if swift(>=6.0)
    let details: [M] = unpackedDetails()
    return details.first
#else
    return unpackedDetails().first
#endif
}
eseay added a commit that referenced this issue Nov 26, 2024
Updates the documentation comment for `ConnectError.unpackedDetails` to
include suggested syntax for accessing the first error of a specific
type in a manner that is compatible with Swift 6 and Xcode 16.x.

For more information, please refer to #323.

Closes #323

Signed-off-by: Eddie Seay <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant