Browse files

Merge pull request #111 from crispinb/master

[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...
2 parents 4dd3a63 + edd79aa commit e834411e2d5886a829e59f941a9ac0719ee22422 @rentzsch committed May 18, 2012
Showing with 18 additions and 0 deletions.
  1. +1 −0 mogenerator.h
  2. +9 −0 mogenerator.m
  3. +8 −0 templates/machine.h.motemplate
View
1 mogenerator.h
@@ -37,6 +37,7 @@
- (NSString*)objectAttributeClassName;
- (NSString*)objectAttributeType;
- (BOOL)hasTransformableAttributeType;
+- (BOOL)isReadonly;
@end
@interface NSRelationshipDescription (collectionClassName)
View
9 mogenerator.m
@@ -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)
View
8 templates/machine.h.motemplate
@@ -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;

0 comments on commit e834411

Please sign in to comment.