# Advice regarding conforming external types to my protocols

**URL:** <https://forums.swift.org/t/advice-regarding-conforming-external-types-to-my-protocols/70875>\
**Category:** Using Swift\
**Tags:** protocols, packagemanager, conformance, swift-package\
**Created:** [March 24, 2024, 5:34pm UTC](https://forums.swift.org/t/advice-regarding-conforming-external-types-to-my-protocols/70875 "2024-03-24T17:34:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeremyabannister](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jeremyabannister/32/10143_2.png) [@jeremyabannister](https://forums.swift.org/u/jeremyabannister)\
**Post date:** [March 24, 2024, 5:34pm UTC](https://forums.swift.org/t/advice-regarding-conforming-external-types-to-my-protocols/70875/1 "2024-03-24T17:34:19Z")

</div>

I'm seeking some advice regarding conforming types that I do not own to protocols defined in my Swift packages. Specifically, I'm wondering about the best way to go about providing conformances for types which otherwise my package does not require.

Let's say `MyPackage` vends protocol `Foo`. Imagine that it is often desirable for `OrderedDictionary` to conform to `Foo`. `MyPackage` does not make use of `OrderedDictionary`, and clients of `MyPackage` will of course not always need `OrderedDictionary` in their code, but in the case that they do need it, it would be desirable for it to conform to `Foo`. I know that in general it is bad practice to conform types that you do not own to protocols that you do not own, which would imply that `MyPackage` should supply the conformance of `OrderedDictionary` to `Foo`. However, I do not want to force a dependency on `swift-collections` onto all of the clients of `MyPackage`.

I'm looking for opinions and advice regarding the best way to handle this type of situation.

---

<div class="post-metadata">

**Author:** ![taylorswift](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/taylorswift/32/43413_2.png) [@taylorswift](https://forums.swift.org/u/taylorswift)\
**Post date:** [March 24, 2024, 6:33pm UTC](https://forums.swift.org/t/advice-regarding-conforming-external-types-to-my-protocols/70875/2 "2024-03-24T18:33:29Z")

</div>

create a module named `_MyPackage_OrderedCollections` that contains the third party dependency and the conformance to your protocol, and expose it as a library product.

SwiftPM and certain external tooling (e.g. VSCode) will perceive an additional dependency, but binaries that depend on `MyPackage` only will not. it is unfortunate that these tools are not intelligent enough to load these package dependencies lazily, but in my opinion that is not a good enough reason to avoid vending the overlay module.

here is an example of this pattern in practice:

> **[swift-mongodb/Sources/BSON\_OrderedCollections at master ·...](https://github.com/tayloraswift/swift-mongodb/tree/master/Sources/BSON_OrderedCollections)**
>
> use BSON and MongoDB in pure Swift. Contribute to tayloraswift/swift-mongodb development by creating an account on GitHub.
