Skip to content

NSDimension -measurementByConvertingToUnit does not work #581

@ashalkhakov

Description

@ashalkhakov

I have this code that works on OSX:

    NSMeasurement *measurement = [[NSMeasurement alloc] initWithDoubleValue:value unit:fromUnit];
    if ([measurement canBeConvertedToUnit:toUnit]) {
        return [measurement measurementByConvertingToUnit:toUnit].doubleValue;
    }

but for GNUstep I have to do instead:

    if ([fromUnit isKindOfClass:[NSDimension class]] && [toUnit isKindOfClass:[NSDimension class]]) {
        NSUnitConverter *fromConv = [(NSDimension *)fromUnit converter];
        NSUnitConverter *toConv   = [(NSDimension *)toUnit converter];
        double baseValue = [fromConv baseUnitValueFromValue:value];
        return [toConv valueFromBaseUnitValue:baseValue];
    }

The code is here. You can comment out the GNUSTEP segment and run XCTest and you'll find that UDUnitConverter fails without the workaround.

I'll probably submit a PR for this, if you think it's worth fixing.

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