Groot icon indicating copy to clipboard operation
Groot copied to clipboard

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

Open bizibizi opened this issue 8 years ago • 5 comments
trafficstars

bizibizi avatar Aug 01 '17 20:08 bizibizi

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

gonzalezreal avatar Aug 02 '17 07:08 gonzalezreal

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?

bizibizi avatar Aug 02 '17 09:08 bizibizi

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

gonzalezreal avatar Aug 02 '17 09:08 gonzalezreal

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

bizibizi avatar Aug 03 '17 09:08 bizibizi

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.

gonzalezreal avatar Aug 03 '17 13:08 gonzalezreal