Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decimal to NSDecimalNumber doesn't work #269

Open
denis-ios opened this issue Feb 7, 2018 · 2 comments
Open

Decimal to NSDecimalNumber doesn't work #269

denis-ios opened this issue Feb 7, 2018 · 2 comments

Comments

@denis-ios
Copy link

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?

@evermeer
Copy link
Owner

evermeer commented Feb 8, 2018

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.

@denis-ios
Copy link
Author

denis-ios commented Feb 8, 2018

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants