Foreverland / SYNCPropertyMapper

Map your Core Data properties with ease
37 stars 16 forks source link

Transformables support #102

Closed AlexKel closed 8 years ago

AlexKel commented 8 years ago

Every once in a while a shitty API comes along :) I've been unfortunate to work with one recently...

I've had an issue with their date object... they've been storing them as strings: "\Date(_timestamp_in_milliseconds_here_)\" I've been using Sync for this project and have been struggling with these dates as I need to be able to do a proper search in my Core Data by date, etc... So, what I figured out could be a solution is to support NSValueTransformers.

In this small PR I've got it working. Anyone who want to transform value before it going to the database needs to implement NSValueTransformer subclass and specify it in their core data model.

If OS for some reason fails to identify and auto-register your transformer, you can do this manually by using setValueTransformer: forName: class function of NSValueTransfomer.

3lvis commented 8 years ago

@AlexKel Hi Aleksandr, first of all, I feel your pain and understand what you have to deal with.

y0dqnm

Hehehe, moving on. Thanks a lot for this PR, I'm sure it will be useful to a lot of people. I found some minor things, besides the typo that makes the build to fail. Great work with the unit tests, I wish more people were as detailed as you.

Please have a look at the PR that I sent to your fork here: https://github.com/AlexKel/NSManagedObject-HYPPropertyMapper/pull/1

AlexKel commented 8 years ago

Hello, Just merged your PR with refactoring, thanks for the input :)

By the way, this kind of helps with this issue: https://github.com/hyperoslo/NSManagedObject-HYPPropertyMapper/issues/71. At least until proper feature implementation :)

3lvis commented 8 years ago

@AlexKel Good point! I'll add a new issue to document how to do that using transformables.

Thanks a lot again, you're the best! 💐

3lvis commented 8 years ago

💥💥💥 Shipped in Sync 1.6.2 💥💥💥

https://github.com/hyperoslo/Sync/releases/tag/1.6.2