All Downloads are FREE. Search and download functionalities are using the official Maven repository.

objc.model-body.mustache Maven / Gradle / Ivy

The newest version!
{{#models}}
{{#model}}
#import "{{classname}}.h"

@implementation {{classname}}

- (instancetype)init {
  self = [super init];
  if (self) {
    // initialize property's default value, if any
    {{#vars}}{{#defaultValue}}self.{{name}} = {{{defaultValue}}};
    {{/defaultValue}}{{/vars}}
  }
  return self;
}
{{#vars}}{{^vendorExtensions.x-unique-id-key}}{{/vendorExtensions.x-unique-id-key}}{{#vendorExtensions.x-unique-id-key}}
-(NSString*)indexPropertyName {
    return @"{{name}}";
}
{{/vendorExtensions.x-unique-id-key}}{{/vars}}
{{#discriminator}}
/**
 * Maps "discriminator" value to the sub-class name, so that inheritance is supported.
 */
- (id)initWithDictionary:(NSDictionary *)dict error:(NSError *__autoreleasing *)err {
    NSString * discriminatedClassName = [dict valueForKey:@"{{discriminator}}"];
    if(discriminatedClassName == nil ){
         return [super initWithDictionary:dict error:err];
    }
    Class class = NSClassFromString([@"{{classPrefix}}" stringByAppendingString:discriminatedClassName]);
    if([self class ] == class) {
        return [super initWithDictionary:dict error:err];
    }
    return [[class alloc] initWithDictionary:dict error: err];
}
{{/discriminator}}

/**
 * Maps json key to property name.
 * This method is used by `JSONModel`.
 */
+ (JSONKeyMapper *)keyMapper {
  return [[JSONKeyMapper alloc] initWithDictionary:@{ {{#vars}}@"{{baseName}}": @"{{name}}"{{#hasMore}}, {{/hasMore}}{{/vars}} }];
}

/**
 * Indicates whether the property with the given name is optional.
 * If `propertyName` is optional, then return `YES`, otherwise return `NO`.
 * This method is used by `JSONModel`.
 */
+ (BOOL)propertyIsOptional:(NSString *)propertyName {

  NSArray *optionalProperties = @[{{#vars}}{{^required}}@"{{name}}"{{#hasMore}}, {{/hasMore}}{{/required}}{{/vars}}];
  return [optionalProperties containsObject:propertyName];
}

{{/model}}
@end
{{/models}}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy