Skip to content

Decimal to NSDecimalNumber doesn't work #269

Open

Description

@denis-ios

Reflection from Decimal to NSDecimalNumber doesn't work due the following error:

'Unacceptable type of value for attribute: property = "FIELD_NAME"; desired type = NSDecimalNumber; given type = __NSDictionaryM; value = {
"_mantissa" = "";
}.'

Sample code:

var toCoreDataModel = CoreDataType(context: ctx)
let dict = fromModel.toDictionary()
toCoreDataModel = EVReflection.setPropertiesfromDictionary(dict, anyObject: toCoreDataModel, conversionOptions: .DefaultDeserialize)

Do you have any clue?

Activity

  1. evermeer commented on Feb 8, 2018

    @evermeer
    Owner

    Apparently a NSDecimalNumber is it's own object with for instance a _mantissa property. If so, then NSDecimalNumber needs to be handled in EVReflection like that or you could make it EVCustomReflectable. I will have a look at this later this weekend.

  2. denis-ios commented on Feb 8, 2018

    @denis-ios
    Author

    Decimal is a struct (a value type bridged to NSDecimalNumber), I can't make it EVCustomReflectable.

    Changing EVReflection seems works from Decimal to NSDecimalNumber:

    if valueType.contains("Decimal") {
        return (theValue as! NSDecimalNumber, "NSDecimalNumber", false)
    } 
    

    but doesn't work from NSDecimalNumber to Decimal:

    anyObject.setValue(setValue, forKey: key)

    it leaves the optional Decimal field as nil

    Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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