Identifiable restricted to iOS 13 for SPM packages?

I thought the protocol being added to Swift 5.1 and its associated standard library. My application is being built with the iOS 13 SDK using Swift 5.1 and I can use other features like Property Wrappers from my swift packages. However, even though I can use Identifiable in my application target (built with the iOS 13 SDK, targeting iOS 10), I cannot use it in a package that declares .iOS(.v10) as its platforms (even though this is also being compiled with the Swift 5.1 compiler). It results in an error stating that Identifiable is only available in iOS 13 and above.

You can see that it's annotated as being iOS 13+ here too:

That's surprising, as I just tested with a simple test project and this doesn't work.
Just create a new project, set the deployment to iOS11 and write in AppDelegate:

if self is Identifiable {
  print("!")
}

and you will get the expected 'Identifiable' is only available in iOS 13 or newer error

1 Like

Yeah I’m super confused - I thought everything in the standard library came bundled with the runtime - i.e. if you can use property wrappers, you’re using the Swift 5.1 compiler and would have access to any Swift 5.1 additions to the Standard Library. The protocol doesn’t even use any Swift 5.1 features!? We could obviously use this as a currency type but hating it on an OS version means no library authors will use this for 3+ years.

It is super annoying things like Identifiable in the standard library are not back-deployable and even more so are not polyfill-able for users.

What's confusing me though is that it should not be possible your project compiles as you said. There are usually correct error messages. Not sure why you are able to use Identifiable without conditionalizing and having a deployment target of iOS10.

Property wrappers were built using code generation, so are backwards deployable (explained here).

The odd thing is the definition literally has @available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *), but it still compiles when targeting my iOS 12 simulator. Strangely enough it does give me the correct error with extension Identifiable { }.

My guess is this is a bug, or there's some automated stripping of unsupported protocols adherence that I'm unaware of. It's possible it will crash on pre-iOS 13 devices, but I don't have one handy to check.

Availability enforces that you can only use something on new enough OSs; it doesn't prevent you from compiling. That's how iOS developers can adopt new features without breaking backwards-deployment.

Hm...so the idea is you can use it in ways where the Type information isn't required at runtime? Is the Identifiable adherence removed for incompatible runtimes, or is it simply never referenced and so would not crash?

Formally, the latter, even though it's implemented as the former (since there's no Identifiable to conform to on iOS 12).

I suppose that would be up to the compiler/runtime. Anyway, that's interesting. Thanks for my TIL!

Terms of Service

Privacy Policy

Cookie Policy