Search code examples
iosrestkit

RestKit: How do you map to NSUUID?


My iOS app is using RestKit to consume a rest api that I control. I am having trouble mapping a UUID field to a local model object’s NSUUID property, simply called uuid. Initially I was formatting the UUID in hex with separated with hyphens and restkit was giving me an error upon realizing that the docs state ``UUIDs created by NSUUID conform to RFC 4122 version 4…’’. So I changed the format to the RFC, but to no avail—error below. Any thoughts on this, perhaps RestKit doesn’t support NSUUID mapping? If so, can you please provide thoughts on how to go about doing so using RestKit v0.24.1, which depends on AFNetworking 1.3.4?

restkit.object_mapping:RKMappingOperation.m:682 Failed transformation of value at keyPath 'uuid' to representation of type 'NSUUID': Error Domain=org.restkit.RKValueTransformers.ErrorDomain Code=3002 "Failed transformation of value '0189fbce661441f6812530785bcb9aef' to NSUUID: none of the 2 value transformers consulted were successful."


Solution

  • If you want to store your value as an NSUUID then you will need to create a custom value transformer to map to and from that class. This wouldn't be very difficult if your string correctly follows the UUID format as NSUUID has initWithUUIDString: and UUIDString methods.