Skip to content

Commit

Permalink
Add scalarsWhenNonOptional TemplateVar
Browse files Browse the repository at this point in the history
If the scalarsWhenNonOptional template var is set to true, and an Attribute is not optional (requires fix for #286), then we'll generate accessor/mutator methods using the plain attribute name rather than with the Value suffix.
  • Loading branch information
Mr Anonymous committed Mar 3, 2016
1 parent d4159ec commit 51e8124
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 8 additions & 0 deletions templates/machine.h.motemplate
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ extern const struct <$managedObjectClassName$>UserInfo {<$foreach UserInfo userI
*/
<$endif$>
<$if Attribute.hasDefinedAttributeType$>
<$if (Attribute.hasScalarAttributeType && !Attribute.optional && TemplateVar.scalarsWhenNonOptional)$>
<$if Attribute.isReadonly$>
@property (atomic, readonly) <$Attribute.scalarAttributeType$> <$Attribute.name$>;
<$else$>
@property (atomic) <$Attribute.scalarAttributeType$> <$Attribute.name$>;
<$endif$>
<$else$>
<$if Attribute.isReadonly$>
@property (nonatomic, strong, readonly) <$Attribute.objectAttributeType$> <$Attribute.name$>;
<$else$>
Expand All @@ -85,6 +92,7 @@ extern const struct <$managedObjectClassName$>UserInfo {<$foreach UserInfo userI
<$endif$>
//- (BOOL)validate<$Attribute.name.initialCapitalString$>:(id*)value_ error:(NSError**)error_;
<$endif$>
<$endif$>
<$endforeach do$>
<$foreach Relationship noninheritedRelationships do$>
<$if Relationship.userInfo.documentation$>
Expand Down
15 changes: 14 additions & 1 deletion templates/machine.m.motemplate
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const struct <$managedObjectClassName$>UserInfo <$managedObjectClassName$>UserIn

+ (NSSet*)keyPathsForValuesAffectingValueForKey:(NSString*)key {
NSSet *keyPaths = [super keyPathsForValuesAffectingValueForKey:key];
<$foreach Attribute noninheritedAttributes do$><$if Attribute.hasDefinedAttributeType$><$if Attribute.hasScalarAttributeType$>
<$foreach Attribute noninheritedAttributes do$><$if Attribute.hasDefinedAttributeType$><$if Attribute.hasScalarAttributeType && (Attribute.optional || !TemplateVar.scalarsWhenNonOptional)$>
if ([key isEqualToString:@"<$Attribute.name$>Value"]) {
NSSet *affectingKey = [NSSet setWithObject:@"<$Attribute.name$>"];
keyPaths = [keyPaths setByAddingObjectsFromSet:affectingKey];
Expand All @@ -68,6 +68,18 @@ const struct <$managedObjectClassName$>UserInfo <$managedObjectClassName$>UserIn
@dynamic <$Attribute.name$>;

<$if Attribute.hasScalarAttributeType$>
<$if (!Attribute.optional && TemplateVar.scalarsWhenNonOptional)$>
- (<$Attribute.scalarAttributeType$>)<$Attribute.name$> {
NSNumber *result = [self primitive<$Attribute.name.initialCapitalString$>];
return [result <$Attribute.scalarAccessorMethodName$>];
}

<$if ! Attribute.isReadonly$>
- (void)set<$Attribute.name.initialCapitalString$>:(<$Attribute.scalarAttributeType$>)value_ {
[self setPrimitive<$Attribute.name.initialCapitalString$>:@(value_)];
}
<$endif$>
<$else$>

- (<$Attribute.scalarAttributeType$>)<$Attribute.name$>Value {
NSNumber *result = [self <$Attribute.name$>];
Expand All @@ -92,6 +104,7 @@ const struct <$managedObjectClassName$>UserInfo <$managedObjectClassName$>UserIn
<$endif$>
<$endif$>
<$endif$>
<$endif$>
<$endforeach do$>

<$foreach Relationship noninheritedRelationships do$>
Expand Down

0 comments on commit 51e8124

Please sign in to comment.