gonzalezreal / Groot

From JSON to Core Data and back.
Other
534 stars 61 forks source link

How to use ValueTransformer in swift3? can you give me a sample pplease #80

Open bizibizi opened 7 years ago

gonzalezreal commented 7 years ago

You can find an example of ValueTransformer in the unit tests: https://github.com/gonzalezreal/Groot/blob/master/GrootTests/SerializationTests.swift#L23

And remember that the value transformer for a property is configured in the .xcdatamodel file: https://github.com/gonzalezreal/Groot/blob/master/GrootTests/Model.xcdatamodeld/Model.xcdatamodel/contents#L39

bizibizi commented 7 years ago

and where should I place the code? I have class Animal, (Animal and _Animal). So, in Animal clasbut in what method? or after/before parsing data?

gonzalezreal commented 7 years ago

The value transformer(s) should be setup once before parsing. Usually application startup is a good place.

bizibizi commented 7 years ago

ok, and type in Model should be Transformable, right? but in that case I will need to convert property to needed type?

gonzalezreal commented 7 years ago

The type in the model doesn't need to be transformable. Please have a look at this document to get to know how Groot annotations work.