<$comment
EOGenerator template for generated classes' Objective-C source files.
This file is a more likely example of one to be actually used
in a production environment.

BE SURE NOT TO INCLUDE DATES IN THIS FILE.  Since the "eogenerator"
tool tries to compare the newly generated file with the old file,
adding dates to this file will guarantee the old file gets
overridden by the new file, forcing a recompilation of your EO.$>

// <$GEN_PREFIX$><$className$>.m
// 
// Created by eogenerator
// DO NOT EDIT.  Make changes to <$className$>.m instead.

#import "<$GEN_PREFIX$><$className$>.h"
#import <Foundation/Foundation.h>
#import <EOControl/EOEditingContext.h>
#import <EOControl/EOClassDescription.h>
<$if FetchSpecs.@count > 0 $>
#import <EOControl/EOFetchSpecification.h>
<$endif$>
<$comment  Use referencedObjCImportStrings instead of referencedClasses
           for better #import handling for cross-framework relationships.
$><$foreach importString referencedObjCImportStrings do$>#import <$importString$>
<$endforeach do$>

@implementation <$GEN_PREFIX$><$className$>

// EOF invokes this init method when creating objects.
- (id)initWithEditingContext:(EOEditingContext *)editingContext classDescription:(EOClassDescription *)classDesc globalID:(EOGlobalID *)gid
{
    self = [super initWithEditingContext:editingContext classDescription:classDesc globalID:gid];
    return self;
}

// This init method is usually used from user code.
- (id)init
{
    self = [super init];
    return self;
}

<$foreach attribute classAttributes.@sortedNameArray do$>
- (void)set<$attribute.name.initialCapitalString$>:(<$attribute.valueClassName$> *)aValue
{
    [self takeStoredValue:aValue forKey:@"<$attribute.name$>"];
}
- (<$attribute.valueClassName$> *)<$attribute.name$>
{
    return [self storedValueForKey:@"<$attribute.name$>"];
}
<$endforeach do$>

<$foreach toOneRelationship classToOneRelationships.@sortedNameArray do$>
- (void)set<$toOneRelationship.name.initialCapitalString$>:(<$toOneRelationship.destinationEntity.referenceClassName$>)aValue
{
    [self takeStoredValue:aValue forKey:@"<$toOneRelationship.name$>"];
}
- (<$toOneRelationship.destinationEntity.referenceClassName$>)<$toOneRelationship.name$>
{
    return [self storedValueForKey:@"<$toOneRelationship.name$>"];
}
- (void)set<$toOneRelationship.name.initialCapitalString$>Relationship:(<$toOneRelationship.destinationEntity.referenceClassName$>)aValue
{
    if (aValue == nil) {
        <$toOneRelationship.destinationEntity.referenceClassName$>object = [self <$toOneRelationship.name$>];
        if (object != nil)
            [self removeObject:object fromBothSidesOfRelationshipWithKey:@"<$toOneRelationship.name$>"];
    }
    else {
        [self addObject:aValue toBothSidesOfRelationshipWithKey:@"<$toOneRelationship.name$>"];
    }
}
<$endforeach do$>

<$foreach toManyRelationship classToManyRelationships.@sortedNameArray do$>
- (void)set<$toManyRelationship.name.initialCapitalString$>:(NSMutableArray *)aValue
{
    [self takeStoredValue:aValue forKey:@"<$toManyRelationship.name$>"];
}
- (NSArray *)<$toManyRelationship.name$>
{
    return [self storedValueForKey:@"<$toManyRelationship.name$>"];
}
- (void)addTo<$toManyRelationship.name.initialCapitalString$>:(<$toManyRelationship.destinationEntity.referenceClassName$>)object
{
    NSMutableArray *array = (NSMutableArray *)[self <$toManyRelationship.name$>];
    [self willChange];
    [array addObject:object];
}
- (void)removeFrom<$toManyRelationship.name.initialCapitalString$>:(<$toManyRelationship.destinationEntity.referenceClassName$>)object
{
    NSMutableArray *array = (NSMutableArray *)[self <$toManyRelationship.name$>];
    [self willChange];
    [array removeObject:object];
}
- (void)addTo<$toManyRelationship.name.initialCapitalString$>Relationship:(<$toManyRelationship.destinationEntity.referenceClassName$>)object
{
    [self addObject:object toBothSidesOfRelationshipWithKey:@"<$toManyRelationship.name$>"];
}
- (void)removeFrom<$toManyRelationship.name.initialCapitalString$>Relationship:(<$toManyRelationship.destinationEntity.referenceClassName$>)object
{
    [self removeObject:object fromBothSidesOfRelationshipWithKey:@"<$toManyRelationship.name$>"];
}
<$endforeach do$>

<$foreach FetchSpec FetchSpecs do$>
+ (NSArray *)objectsFor<$FetchSpec.niceName$>:(EOEditingContext *)context<$foreach Binding FetchSpec.bindings do2$> <$Binding.name$>:(<$Binding.codeType$>)<$Binding.name$>Binding<$endforeach do2$>
{
    EOFetchSpecification *spec = [EOFetchSpecification fetchSpecificationNamed:@"<$FetchSpec.fetchName$>" entityNamed:@"<$name$>"];<$if FetchSpec.bindings.@count gt 0$>
    NSMutableDictionary *bindings = [NSMutableDictionary dictionary];
<$foreach Binding FetchSpec.bindings do2$>
    if ( <$Binding.name$>Binding != nil )
        [bindings setObject:<$Binding.name$>Binding forKey:@"<$Binding.name$>"];<$endforeach do2$>
    spec = [spec fetchSpecificationWithQualifierBindings:bindings];
<$endif$>
    return [context objectsWithFetchSpecification:spec];
}
<$endforeach do$>
@end