objc.NSManagedObjectBuilder-body.mustache Maven / Gradle / Ivy
{{#models}}{{#model}}
#import "{{classname}}ManagedObjectBuilder.h"
/**
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen
* Do not edit the class manually.
*/
@implementation {{classname}}ManagedObjectBuilder
-(instancetype)init {
self = [super init];
if (self != nil) {
{{#isArrayModel}} _entriesBuilder = [[{{arrayModelType}}ManagedObjectBuilder alloc] init];
{{/isArrayModel}}{{#vars}}{{#complexType}}{{^isMapContainer}} _{{name}}Builder = [[{{complexType}}ManagedObjectBuilder alloc] init];
{{/isMapContainer}}{{/complexType}}{{/vars}} }
return self;
}
-({{classname}}ManagedObject*)createNew{{classname}}ManagedObjectInContext:(NSManagedObjectContext*)context {
{{classname}}ManagedObject *managedObject = [NSEntityDescription insertNewObjectForEntityForName:NSStringFromClass([{{classname}}ManagedObject class]) inManagedObjectContext:context];
return managedObject;
}
-({{classname}}ManagedObject*){{classname}}ManagedObjectFrom{{classname}}:({{classname}}*)object context:(NSManagedObjectContext*)context {
{{classname}}ManagedObject* new{{classname}} = [self createNew{{{classname}}}ManagedObjectInContext:context];
[self update{{classname}}ManagedObject:new{{classname}} with{{classname}}:object];
return new{{classname}};
}
-(void)update{{classname}}ManagedObject:({{classname}}ManagedObject*)managedObject with{{classname}}:({{classname}}*)object {
if(!managedObject || !object) {
return;
}
NSManagedObjectContext* context = managedObject.managedObjectContext;
{{#vars}}{{^complexType}} managedObject.{{name}} = [object.{{name}} copy];{{/complexType}}{{#complexType}}{{#isListContainer}} if(managedObject.{{name}}) {
for (id object in managedObject.{{name}}) {
[context deleteObject:object];
}
}
if(object.{{name}}) {
NSMutableOrderedSet * convertedObjs = [NSMutableOrderedSet orderedSet];
for (id innerObject in object.{{name}}) {
id convertedObj = [self.{{name}}Builder {{complexType}}ManagedObjectFrom{{complexType}}:innerObject context:managedObject.managedObjectContext];
[convertedObjs addObject:convertedObj];
}
managedObject.{{name}} = convertedObjs;
}{{/isListContainer}}{{^isListContainer}}{{^isMapContainer}}
if(!managedObject.{{name}}) {
managedObject.{{name}} = [self.{{name}}Builder {{complexType}}ManagedObjectFrom{{complexType}}:object.{{name}} context:managedObject.managedObjectContext];
} else {
[self.{{name}}Builder update{{complexType}}ManagedObject:managedObject.{{name}} with{{complexType}}:object.{{name}}];
}{{/isMapContainer}}{{#isMapContainer}}managedObject.{{name}} = [object.{{name}} copy];{{/isMapContainer}}{{/isListContainer}}{{/complexType}}
{{/vars}}{{#isArrayModel}} NSMutableOrderedSet * convertedObjs = [NSMutableOrderedSet orderedSet];
for (id innerObject in object) {
id convertedObj = [self.entriesBuilder {{arrayModelType}}ManagedObjectFrom{{arrayModelType}}:innerObject context:managedObject.managedObjectContext];
[convertedObjs addObject:convertedObj];
}
managedObject.entries = convertedObjs;{{/isArrayModel}}
}
-({{classname}}*){{classname}}From{{classname}}ManagedObject:({{classname}}ManagedObject*)obj {
if(!obj) {
return nil;
}
{{classname}}* new{{classname}} = [[{{classname}} alloc] init];
[self update{{classname}}:new{{classname}} with{{classname}}ManagedObject:obj];
return new{{classname}};
}
-(void)update{{classname}}:({{classname}}*)new{{classname}} with{{classname}}ManagedObject:({{classname}}ManagedObject*)obj {
{{#isArrayModel}} [new{{classname}} removeAllObjects];
NSMutableArray* convertedObjs = [NSMutableArray array];
for (id innerObject in obj.entries) {
id convertedObj = [self.entriesBuilder {{arrayModelType}}From{{arrayModelType}}ManagedObject:innerObject];
[convertedObjs addObject:convertedObj];
}
[new{{classname}} addObjectsFromArray:convertedObjs];
{{/isArrayModel}}{{#vars}}{{^complexType}} new{{classname}}.{{name}} = [obj.{{name}} copy];{{/complexType}}{{#complexType}}{{#isListContainer}} if(obj.{{name}} != nil) {
NSMutableArray* convertedObjs = [NSMutableArray array];
for (id innerObject in obj.{{name}}) {
id convertedObj = [self.{{name}}Builder {{complexType}}From{{complexType}}ManagedObject:innerObject];
[convertedObjs addObject:convertedObj];
}
new{{classname}}.{{name}} = ({{{ datatype }}})convertedObjs;
}
{{/isListContainer}}{{^isListContainer}} new{{classname}}.{{name}} = [self.{{name}}Builder {{complexType}}From{{complexType}}ManagedObject:obj.{{name}}];{{/isListContainer}}{{/complexType}}
{{/vars}}
}
@end
{{/model}}
{{/models}}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy