0

Is any way to use Restkit framework to map json (nsdictionary) to object without request.

i have json and need to map it in object

Stalik
  • 1

1 Answers1

0

You can use RKMappingOperation class. This is example from documentation:

@interface RKMetadataExample : NSObject
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSURL *URL;
@property (nonatomic, copy) NSDate *mappedAt;
@end

RKMetadataExample *example = [RKMetadataExample new];
NSDictionary *representation = @{ @"name": @"Blake Watters" };
NSDictionary *metadata = @{ @"URL": [NSURL URLWithString:@"http://restkit.org"] };

RKObjectMapping *objectMapping = [RKObjectMapping mappingForClass:[RKMetadataExample class]];
[objectMapping addAttributeMappingsFromDictionary:@{ @"name": @"name", @"@metadata.URL": @"URL" }];

RKMappingOperation *mappingOperation = [[RKMappingOperation alloc] initWithSourceObject:representation destinationObject:example mapping:objectMapping];
mappingOperation.metadata = metadata;

NSError *error = nil;
BOOL success = [mappingOperation execute:&error];
Sergey
  • 1,589
  • 9
  • 13