Skip to content

Commit

Permalink
Merge pull request #111 from crispinb/master
Browse files Browse the repository at this point in the history
[NEW] Generated attribute @Property declarations can include the readonly modifier. Invoke by adding an entry with the key `mogenerator.readonly` to the attribute's user info (leave the value empty -- the presence of the key is enough). (crispinb)
  • Loading branch information
rentzsch committed May 18, 2012
2 parents 4dd3a63 + edd79aa commit e834411
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions mogenerator.h
Expand Up @@ -37,6 +37,7 @@
- (NSString*)objectAttributeClassName;
- (NSString*)objectAttributeType;
- (BOOL)hasTransformableAttributeType;
- (BOOL)isReadonly;
@end

@interface NSRelationshipDescription (collectionClassName)
Expand Down
9 changes: 9 additions & 0 deletions mogenerator.m
Expand Up @@ -356,6 +356,15 @@ - (NSString*)objectAttributeType {
- (BOOL)hasTransformableAttributeType {
return ([self attributeType] == NSTransformableAttributeType);
}

- (BOOL)isReadonly {
NSString *readonlyUserinfoValue = [[self userInfo] objectForKey:@"mogenerator.readonly"];
if (readonlyUserinfoValue != nil) {
return YES;
}
return NO;
}

@end

@implementation NSRelationshipDescription (collectionClassName)
Expand Down
8 changes: 8 additions & 0 deletions templates/machine.h.motemplate
Expand Up @@ -32,10 +32,18 @@ extern const struct <$managedObjectClassName$>FetchedProperties {<$foreach Fetch
<$foreach Attribute noninheritedAttributes do$>
<$if Attribute.hasDefinedAttributeType$>
<$if TemplateVar.arc$>
<$if Attribute.isReadonly$>
@property (nonatomic, strong, readonly) <$Attribute.objectAttributeType$> <$Attribute.name$>;
<$else$>
@property (nonatomic, strong) <$Attribute.objectAttributeType$> <$Attribute.name$>;
<$endif$>
<$else$>
<$if Attribute.isReadonly$>
@property (nonatomic, retain, readonly) <$Attribute.objectAttributeType$> <$Attribute.name$>;
<$else$>
@property (nonatomic, retain) <$Attribute.objectAttributeType$> <$Attribute.name$>;
<$endif$>
<$endif$>
<$if Attribute.hasScalarAttributeType$>
@property <$Attribute.scalarAttributeType$> <$Attribute.name$>Value;
- (<$Attribute.scalarAttributeType$>)<$Attribute.name$>Value;
Expand Down

0 comments on commit e834411

Please sign in to comment.