测试已测试 | ✗ |
语言语言 | Obj-CObjective C |
许可证 | MIT |
发布最新发布 | 2016年4月 |
由Alfie Hanssen、Rob Huebner、Gavin King维护。
VIMObjectMapper
将 JSON 转换为模型对象。
将 VIMObjectMapper
添加到您的项目中。您可以将其包括为 Git 子模块,或使用 cocoapods。
# Add this to your podfile
target 'MyTarget' do
pod 'VIMObjectMapper', '{CURRENT_POD_VERSION}'
end
将您的自定义模型对象变为 VIMModelObject
的子类,并可选实现 VIMMappable
协议的方法。
#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];
请将其提交到 git 问题跟踪器。
如果您想贡献力量,请查看我们在 CONTRIBUTING.md 中的指南。
VIMObjectMapper
在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。
在这里 tweet 给我们:@vimeoapi。
在带有 vimeo-ios
标签的 Stackoverflow 上发表帖子。
在这里联系:这里。
对在 Vimeo 工作感兴趣?我们正在招聘!