TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Apr 2016 |
Maintained by Alfie Hanssen, Rob Huebner, Gavin King.
VIMObjectMapper
converts JSON into model objects.
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
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
}
{
user = {
name = "Homer Simpson";
pictures = {
uri = "...";
sizes = (...);
};
"upload_quota" = { ... };
websites = ( ... );
};
}
NSDictionary *JSON = ...;
VIMObjectMapper *mapper = [[VIMObjectMapper alloc] init];
[mapper addMappingClass:[VIMUser class] forKeypath:@"user"];
VIMUser *user = [mapper applyMappingToJSON:JSON];
Please file it in the git issue tracker.
If you'd like to contribute, please follow our guidelines found in CONTRIBUTING.md.
VIMObjectMapper
is available under the MIT license. See the LICENSE file for more info.
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!