Latest 1.0.5
Homepage https://github.com/asaake/MGObjectMapper
License MIT
Platforms ios 6.0
Authors

Objective-C JSON, Dictionary Mapping Library.

Install

platform :ios, '6.0'
pod "MGObjectMapper", "~> 1.0.5"

Usage

@interface MGMockObject : NSObject<MGObjectMapperResource>
@property (nonatomic) NSString *name;
@property (nonatomic) NSUInteger age;
@end

@implementation MGMockObject

+ (NSDictionary *)keyPathsByPropertyKey
{
    return @{
            @"name": @"my_name",
            @"age": @"age"
    };
}

@end

NSDictionary *jsonData = @{
        @"my_name": @"taro",
        @"age": @(30)
};
MGMockObject *object = [MGObjectMapper modelOfClass:MGMockObject.class fromDictionary:jsonData];
[object name] #=> taro
[object age]  #=> 30

Options

default value
set the default value at the time of initialization.
if NSNull object had entered, it converted to the default value.

+ (NSDictionary *)defaultPropertyValues
{
    return @{
            @"name": @"none_name",
            @"date": [NSDate dateWithTimeIntervalSince1970:0]
    };
}

transform value
related objc or objects

+ (NSDictionary *)transformersByPropertyKey
{
    return @{
            @"date": [[MGDateTransformer alloc] init],
            @"url": [[MGURLTransformer alloc] init],
            @"relatedObject": [[MGObjectTransformer alloc] initWithClass:[MGMockObject class]],
            @"relatedArrayObject": [[MGObjectTransformer alloc] initWithClass:[MGMockObject class]]
    };
}

setter value

+ (NSDictionary *)importSelectorsByPropertyKey
{
    return @{
            @"selectorName": [NSValue valueWithPointer:@selector(importSelectorNameValue:)]
    };
}

- (void)importSelectorNameValue:(id)value
{
    self.selectorName = [((NSString *)value) stringByAppendingString:@"Selector"];
    self.reSelectorName = self.selectorName;
}

null object skip

+ (NSDictionary *)nullObjectSkipsByPropertyKey
{
    return @{
            @"name": @(YES),
            @"memo": @(NO)
    };

    // all skip
    return [MGObjectMapper nullObjectAllSkips];
}

Latest podspec

{
    "name": "MGObjectMapper",
    "version": "1.0.5",
    "summary": "Objective-C JSON, Dictionary Mapping Library.",
    "description": "                   A longer description of MGObjectMapper in Markdown format.nn                   * Think: Why did you write this? What is the focus? What does it do?n                   * CocoaPods will be using this to generate tags, and improve search results.n                   * Try to keep it short, snappy and to the point.n                   * Finally, don't worry about the indent, CocoaPods strips it!n",
    "homepage": "https://github.com/asaake/MGObjectMapper",
    "license": "MIT",
    "authors": {
        "_empty_": ""
    },
    "platforms": {
        "ios": "6.0"
    },
    "source": {
        "git": "https://github.com/asaake/MGObjectMapper.git",
        "tag": "1.0.5"
    },
    "source_files": [
        "MGObjectMapper/Classes",
        "MGObjectMapper/Classes/**/*.{h,m}"
    ],
    "exclude_files": "MGObjectMapper/Classes/Exclude"
}

Pin It on Pinterest

Share This