EVReflection
EVReflection copied to clipboard
Decimal to NSDecimalNumber doesn't work
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?
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.
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.