How, or can you, define conformances for a type in a library?

I've created a library that defines an encoded reference type, and was in the process of adding Transferrable conformance to the main class that represents the data. Doing so wants a type defined for the transferrable, so I'm adding a type for this data representation into the library.

The extension on UniformTypeIdentifiers is trivial, but I'd like to also mark that the type itself conforms to public.data (UTType.data). Since this is in a swift package, there isn't an application-relevant Info.plist that would normally hold these additional details.

Can I add the conformance through the library? Or is the whole aspect of Transferrable and associated UTTypes expected to be something only defined at the application level?

Accepted Reply

Can I add the conformance through the library?

No. You’ll have to instruct your library’s clients to add this conformance to their Info.plist.

Share and Enjoy

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

Replies

Can I add the conformance through the library?

No. You’ll have to instruct your library’s clients to add this conformance to their Info.plist.

Share and Enjoy

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

Earlier I wrote:

No.

While it’s true that a library can’t define types via its Info.plist, a colleague pointed out to me that this isn’t the whole story. If you’re working with Transferable and need to define a UTI for your own internal use, you can do that using the UTType.init(exportedAs:conformingTo:) initialiser.

Share and Enjoy

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

wiqimir wrote:

Defining conformances for a type within a library is indeed possible and a fundamental aspect of extending and customizing the behavior of types.

Did you generate that with some sort of LLM tool? ’cause it’s kinda off-topic for this discussion, which is about Uniform Type Identifiers, not language-level types.

Share and Enjoy

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