# Best approach for Codable on Types I don't own

**URL:** <https://forums.swift.org/t/best-approach-for-codable-on-types-i-dont-own/28915>\
**Category:** Using Swift\
**Created:** [September 18, 2019, 12:55am UTC](https://forums.swift.org/t/best-approach-for-codable-on-types-i-dont-own/28915 "2019-09-18T00:55:41Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![lukasa](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lukasa/32/1232_2.png) [@lukasa](https://forums.swift.org/u/lukasa)\
**Post date:** [September 18, 2019, 9:45am UTC](https://forums.swift.org/t/best-approach-for-codable-on-types-i-dont-own/28915/4 "2019-09-18T09:45:03Z")

</div>

> [@GalCohen](#):
>
> I could create a `MyPoint` type, and use it instead, but I'd really rather not have to update the entire codebase.

You shouldn't have to update the _whole_ codebase.

The only things that absolutely must be updated are the types that currently store `CGPoint` and that are `Codable`. Those types will need to be refactored to actually store a `MyPoint`, and then to expose getters/setters that can turn that `MyPoint` into a `CGPoint` and back again. The `MyPoint` can be an artefact only of the storage.

If you are willing to go further and write custom `Codable` implementations (which you'll have to do for `MyPoint` at least anyway), you can even avoid storing a `MyPoint` at all: just create it in your implementation of `init(from:)` and `encode(to:)`. Then the rest of your codebase can continue to store and work on `CGPoint`s, and only the types that need to be able to serialise themselves have to worry about how it's done.

---

_[View the full topic](https://forums.swift.org/t/best-approach-for-codable-on-types-i-dont-own/28915)._
