Skip to content

Extract Double conversion extensions to a separate target. Consider Measurement. #74

@scottrhoyt

Description

@scottrhoyt

First of all, thanks for the library and great work!

This library exports some Double extensions for conveniently converting different units of length to meters.

I use a similar approach in one of my projects except I use Foundation's Measurement type to encode both values and units.

let length = 2.5.miles // Equivalent to Measurement(value: 2.5, unit: UnitLength.miles)
print(length.converted(to: .meters)) // 4023

I find passing measurements around (when dealing with user I/O especially) is more convenient as I can deal with conversions easily where I need them (e.g. meters for calculations, miles for display, .etc) without enforcing that every length value is in meters. There are also some convenient methods for parsing strings into measurements with different units.

The problem is that my internal extensions conflict with the ones exported by this library. Since these are generally just convenience methods for writing tests, mocks, or similar hand-coded data, I'd like to propose that these extensions get pulled out into a separate target (e.g. GISToolsConversions) for selective inclusion in these use cases. Also, you can consider if the Measurement approach works better for you as well.

Happy to send over a PR with these changes, but as this is a breaking change, I wanted to discuss its viability first.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions