<TRCValueTransformer > Protocol Reference

TRCValueTransformer aimed to convert simple (atomic) typed objects, received as response, into objects to use inside app, and vise versa. More...

Inheritance diagram for <TRCValueTransformer >:

Instance Methods

(id) - objectFromResponseValue:error:
 Converts received value into custom object. More...
 
(id) - requestValueFromObject:error:
 Converts object into value which can be used in request. More...
 
(TRCValueTransformerType- externalTypes
 BitMask of value types (TRCValueTransformerType), used in request and response. More...
 

Detailed Description

TRCValueTransformer aimed to convert simple (atomic) typed objects, received as response, into objects to use inside app, and vise versa.

Examples:

  • Convert received NSString into NSURL
  • Convert NSDate in request into NSString(using special formatting) or NSNumber(unix time)
  • Convert received string value into something like ENUM, or custom object

Method Documentation

◆ objectFromResponseValue:error:()

- (id TRCValueTransformer) objectFromResponseValue: (id)  responseValue
error: (NSError **)  error 

Converts received value into custom object.

Parameters
responseValueinput value to process, has external type (type which can be used in your serialization format)
errorpointer to write back
Returns
returns value to use in the app

◆ requestValueFromObject:error:()

- (id TRCValueTransformer) requestValueFromObject: (id)  object
error: (NSError **)  error 

Converts object into value which can be used in request.

Parameters
objectobject specified in request
errorerror to write back
Returns
value which can be used in request (type allowed by your serialization format)

◆ externalTypes()

- (TRCValueTransformerType TRCValueTransformer) externalTypes
optional

BitMask of value types (TRCValueTransformerType), used in request and response.

Used for validation purpose. If not implemented, TRCValueTransformerTypeString is assumed

external means that these types used outside the app, so we have to convert them into app's types. For example JSON has only number and string value - they are external types. Inside app we have NSData and we want to send it to the server we can't send our NSDate using JSON directly, but we can convert NSDate into NSNumber or NSString. This method declares acceptable types, that sounds like 'this value transformer accepts NSNumber for response value and at same time, it converts NSDate into NSNumber'.

See TRCValueTransformerType for more details about available values

Validation examples:

  • If external type is TRCValueTransformerTypeString but received response value is not string, that will cause validation error.
  • If external type is TRCValueTransformerTypeString but request value after transforming is not string, that also will cause a validation error.