Best approach for Codable on Types I don't own

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 CGPoints, and only the types that need to be able to serialise themselves have to worry about how it's done.

1 Like