Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import "{{ name }}.h"
- @implementation {{ name }}
- {% for f in fields %}
- @synthesize {{ f.name }} = {{ f.name }}_;
- {%- endfor %}
- - (id)initWithDict:(NSDictionary*)dict
- {
- if (![super init])
- return;
- {% for f in fields if not f.primitive %}
- self.{{ f.name }} = [dict objectForKey:@"{{ f.name }}"];
- {%- endfor %}
- return self;
- }
- - (void)dealloc
- {
- {%- for f in fields if not f.primitive %}
- [{{ f.name }}_ release];
- {%- endfor %}
- [super dealloc];
- }
- {% for f in fields %}
- - (void)set{{ f.name|capitalize }}:({{ f.field_type }}){{ f.name }}
- {
- if ({{ f.name }}_ == {{ f.name }})
- return;
- {% for c in f.constraints -%}
- {%- if c[0] == 'required' and c[1] == True %}
- NSAssert({{ f.name }}, @"Required field {{ f.name }} is absent or null");
- {%- elif c[0] == 'minimum' %}
- NSAssert([{{ f.name }} compare:[NSNumber numberWithInt:{{ c[1] }}]] == NSOrderedDescending,
- @"{{ f.name }} > {{ c[1] }} not satisfied");
- {% else %}
- // {{ c }}
- {% endif %}
- {%- endfor %}
- [{{ f.name }}_ release];
- {{ f.name }}_ = [{{ f.name }} retain];
- }
- {% endfor %}
- @end
Add Comment
Please, Sign In to add comment