ios - RestKit .20.x value transformation -
i new ios development , trying custom value transformation in restkit, can't figure out how it. have 2 current problems:
i have base64 encoded image returning in json message server. in below format. using core data backend persistent store , 'image' field stored in core data binary data (nsdata). when restkit transforms base64 encoded image nsdata object, goes wrong because image bytes stored in sqllite database not correct , can't redisplay image.
"images": [{ "id": 1, "recordid": 1, "status": "c", "type": "mugshot", "format": "jpeg", "width": 50, "height": 50, "image": "/9j/4aaqskzjrgabaqeblaesaa....", "createby": "blah", "createdt": 1395683191483, "capturedevice": null }]
- the createby date in ms since epoch, isn't being transformed correctly nsdate object. understand expecting value in seconds, assume causing problem.
after googling, found rkvaluetransformer allow me set custom transformations different classes (in case, i'd want set custom transformer nsdate , nsdata classes. however, rkblockvaluetransformer class referenced here (https://github.com/restkit/restkit/wiki/object-mapping) under "customizing value transformation" section doesn't appear exist me. using restkit .20.3 , used cocoapods install podfile:
platform :ios, '7.0' pod 'restkit', '~> 0.20.3'
i tried adding pod 'rkvaluetransformers', '~> 1.0.0' podfile, caused compiler issues. plus, isn't rkvaluetransformers project extract of value transformation feature built restkit?
am on right path using rkvaluetransformer nsdate , nsdata behavior looking for? if so, have included in project? there easier ways application correctly handle base64 encoded images stored in core data binary field?
edit: here rkvaluetransformers.h , .m file in pods project. appears date formatter related:
if you're storing image data in core data should think ticking 'allow external storage' option.
the value transformer want convert nsstring
nsdata
, need base64 in middle. need create class conforms < rkvaluetransforming >
. because transforming nsstring
should implement validatetransformationfromclass:toclass:
can reject transformation destination isn't nsdata
efficiently.
once have created class , in instance of (imageformatter
), install with:
[[rkvaluetransformer defaultvaluetransformer] insertvaluetransformer:imageformatter atindex:0];
and same process applies date formatter.
Comments
Post a Comment