@available on structure extensions

Hello all,

I have a compilation error that I don't really understand. Perhaps you could enlighten me.
I managed to reduce my problem to this small capture

Does anyone know why the compiler complains about encode method being necessary in iOS 10 +, even if the extension in itself is only available post iOS 13 ? :sweat_smile:

FYI : iOS 10.0.0 is the target version of the library the piece of code belongs to.

Thank you in advance

Swift does not support @available protocol conformance.

Thank you for your answer. That explains it. It does seem to work with some protocol conformance however. This code works for instance :

struct A { }
@available(iOS 13, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
extension A: Identifiable {
    var id: String {
        "someId"
    }
}

Is it because Identifiable is available starting with iOS 13 while Encodable is available on all versions ?

Correct.

OK thanks a lot :)

Terms of Service

Privacy Policy

Cookie Policy