EVReflection icon indicating copy to clipboard operation
EVReflection copied to clipboard

Decimal to NSDecimalNumber doesn't work

Open denis-ios opened this issue 7 years ago • 2 comments
trafficstars

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?

denis-ios avatar Feb 07 '18 17:02 denis-ios

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.

evermeer avatar Feb 08 '18 06:02 evermeer

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.

denis-ios avatar Feb 08 '18 08:02 denis-ios