Guest User

Untitled

a guest
Nov 24th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #import "{{ name }}.h"
  2.  
  3. @implementation {{ name }}
  4.  
  5. {% for f in fields %}
  6. @synthesize {{ f.name }} = {{ f.name }}_;
  7. {%- endfor %}
  8.  
  9. - (id)initWithDict:(NSDictionary*)dict
  10. {
  11. if (![super init])
  12. return;
  13. {% for f in fields if not f.primitive %}
  14. self.{{ f.name }} = [dict objectForKey:@"{{ f.name }}"];
  15. {%- endfor %}
  16.  
  17. return self;
  18. }
  19.  
  20. - (void)dealloc
  21. {
  22. {%- for f in fields if not f.primitive %}
  23. [{{ f.name }}_ release];
  24. {%- endfor %}
  25.  
  26. [super dealloc];
  27. }
  28.  
  29. {% for f in fields %}
  30. - (void)set{{ f.name|capitalize }}:({{ f.field_type }}){{ f.name }}
  31. {
  32. if ({{ f.name }}_ == {{ f.name }})
  33. return;
  34.  
  35. {% for c in f.constraints -%}
  36. {%- if c[0] == 'required' and c[1] == True %}
  37. NSAssert({{ f.name }}, @"Required field {{ f.name }} is absent or null");
  38. {%- elif c[0] == 'minimum' %}
  39. NSAssert([{{ f.name }} compare:[NSNumber numberWithInt:{{ c[1] }}]] == NSOrderedDescending,
  40. @"{{ f.name }} > {{ c[1] }} not satisfied");
  41. {% else %}
  42. // {{ c }}
  43. {% endif %}
  44. {%- endfor %}
  45.  
  46. [{{ f.name }}_ release];
  47. {{ f.name }}_ = [{{ f.name }} retain];
  48. }
  49. {% endfor %}
  50.  
  51. @end
Add Comment
Please, Sign In to add comment