An automatic JSON to model object converter
Objective-C Ruby
Latest commit 2d63582 May 25, 2016 @huebnerob huebnerob Update README.md
Permalink
Failed to load latest commit information.
.github
Examples/VimeoObjectMapper-iOS
VIMObjectMapper.xcworkspace
VimeoObjectMapper
.gitignore
LICENSE.md
README.md
VIMObjectMapper.podspec

README.md

Attention: This tool will be merged into VimeoNetworking shortly. Please refer to that repository for future development. If you're only interested in object mapping, you can use the Models subspec of the VimeoNetworking CocoaPod

VIMObjectMapper

VIMObjectMapper converts JSON into model objects.

Setup

Add VIMObjectMapper to your project. Do this by including it as a git submodule or by using cocoapods:

# Add this to your podfile
target 'MyTarget' do
    pod 'VIMObjectMapper', '{CURRENT_POD_VERSION}'
end

Usage

Subclass VIMModelObject

Make your custom model object a subclass of VIMModelObject and optionally implement the VIMMappable protocol methods:

#import "VIMModelObject.h"

@class VIMPictureCollection;

@interface VIMUser : VIMModelObject

@property (nonatomic, copy) NSString *name;
@property (nonatomic, strong) VIMPictureCollection *pictureCollection;
@property (nonatomic, strong) NSDictionary *uploadQuota;
@property (nonatomic, strong) NSArray *websites;

@end
#import "VIMUser.h"
#import "VIMPictureCollection.h"
#import "VIMObjectMapper.h"

@implementation VIMUser

#pragma mark - VIMMappable // All methods are optional, implement to specify how the object should be "inflated"

- (NSDictionary *)getObjectMapping
{
    return @{@"pictures": @"pictureCollection"};
}

- (Class)getClassForCollectionKey:(NSString *)key
{
    if ([key isEqualToString:@"uploadQuota"])
    {
        return [NSDictionary class];
    }

    if ([key isEqualToString:@"websites"])
    {
        return [NSArray class];
    }

    return nil;
}

- (Class)getClassForObjectKey:(NSString *)key
{
    if ([key isEqualToString:@"pictures"])
    {
        return [VIMPictureCollection class];
    }

    return nil;
}

- (void)didFinishMapping
{
    // Do any post-parsing work you might want to do
}

Get some JSON

{
    user = {
        name = "Homer Simpson";
        pictures = {
            uri = "...";
            sizes = (...);
        };
        "upload_quota" = { ... };
        websites = ( ... );
    };
}

Let VIMObjectMapper go to work

NSDictionary *JSON = ...;

VIMObjectMapper *mapper = [[VIMObjectMapper alloc] init];

[mapper addMappingClass:[VIMUser class] forKeypath:@"user"];

VIMUser *user = [mapper applyMappingToJSON:JSON];

Found an Issue?

Please file it in the git issue tracker.

Want to Contribute?

If you'd like to contribute, please follow our guidelines found in CONTRIBUTING.md.

License

VIMObjectMapper is available under the MIT license. See the LICENSE file for more info.

Questions?

Tweet at us here: @vimeoapi.

Post on Stackoverflow with the tag vimeo-ios.

Get in touch here.

Interested in working at Vimeo? We're hiring!