Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add constant structs for the property names #72

Merged
merged 1 commit into from

4 participants

@danielctull

Sampling Mike Ash's post about namespaced constants (http://www.mikeash.com/pyblog/friday-qa-2011-08-19-namespaced-constants-and-functions.html), this adds the generation of constant structs to access the attribute, relationship and fetched property names. This makes sure that when you're creating a fetch request, you can use these values to guarantee their existence.

@danielctull danielctull Add constant structs for the property names
Sampling Mike Ash's post about namespaced constants (http://www.mikeash.com/pyblog/friday-qa-2011-08-19-namespaced-constants-and-functions.html), this adds the generation of constant structs to access the attribute, relationship and fetched property names. This makes sure that when you're creating a fetch request, you can use these values to guarantee their existence.
cd9dcb8
@extremeboredom

Sounds like an awesome addition, looking forward to using it.

Should it be optionally enabled perhaps, instead of always on? Should be simple with template vars.

@danielctull

I did wonder whether it should be optional, though I can't see too much harm in generating them and not using them, especially if it removes a preference. (Though I know the command line types love options!)

@rentzsch rentzsch merged commit 778bf54 into rentzsch:master
@rentzsch
Owner

I'm going to have it always-on. I don't see a big win being able to turn it off.

@jdmuys

These added structs are incompatible with ARC. I get compiler errors "error: ARC forbids Objective-C objects in structs or unions"

@danielctull

Are you using the ARC flag (--template-var arc=true)? I've been using them solely with ARC since August. :)

@rentzsch
Owner

@jdmuys, @danielctull thanks for clearing this up, it will go in v1.24's changelog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 30, 2011
  1. @danielctull

    Add constant structs for the property names

    danielctull authored
    Sampling Mike Ash's post about namespaced constants (http://www.mikeash.com/pyblog/friday-qa-2011-08-19-namespaced-constants-and-functions.html), this adds the generation of constant structs to access the attribute, relationship and fetched property names. This makes sure that when you're creating a fetch request, you can use these values to guarantee their existence.
This page is out of date. Refresh to see the latest.
Showing with 24 additions and 0 deletions.
  1. +12 −0 templates/machine.h.motemplate
  2. +12 −0 templates/machine.m.motemplate
View
12 templates/machine.h.motemplate
@@ -4,6 +4,18 @@
#import <CoreData/CoreData.h>
<$if hasCustomSuperentity$>#import "<$customSuperentity$>.h"<$endif$>
+extern const struct <$managedObjectClassName$>Attributes {<$foreach Attribute noninheritedAttributes do$>
+ <$if TemplateVar.arc$>__unsafe_unretained<$endif$> NSString *<$Attribute.name$>;<$endforeach do$>
+} <$managedObjectClassName$>Attributes;
+
+extern const struct <$managedObjectClassName$>Relationships {<$foreach Relationship noninheritedRelationships do$>
+ <$if TemplateVar.arc$>__unsafe_unretained<$endif$> NSString *<$Relationship.name$>;<$endforeach do$>
+} <$managedObjectClassName$>Relationships;
+
+extern const struct <$managedObjectClassName$>FetchedProperties {<$foreach FetchedProperty noninheritedFetchedProperties do$>
+ <$if TemplateVar.arc$>__unsafe_unretained<$endif$> NSString *<$FetchedProperty.name$>;<$endforeach do$>
+} <$managedObjectClassName$>FetchedProperties;
+
<$foreach Relationship noninheritedRelationships do$>@class <$Relationship.destinationEntity.managedObjectClassName$>;
<$endforeach do$>
<$foreach Attribute noninheritedAttributes do$><$if Attribute.hasTransformableAttributeType$>@class <$Attribute.objectAttributeType$>;<$endif$>
View
12 templates/machine.m.motemplate
@@ -3,6 +3,18 @@
#import "_<$managedObjectClassName$>.h"
+const struct <$managedObjectClassName$>Attributes <$managedObjectClassName$>Attributes = {<$foreach Attribute noninheritedAttributes do$>
+ .<$Attribute.name$> = @"<$Attribute.name$>",<$endforeach do$>
+};
+
+const struct <$managedObjectClassName$>Relationships <$managedObjectClassName$>Relationships = {<$foreach Relationship noninheritedRelationships do$>
+ .<$Relationship.name$> = @"<$Relationship.name$>",<$endforeach do$>
+};
+
+const struct <$managedObjectClassName$>FetchedProperties <$managedObjectClassName$>FetchedProperties = {<$foreach FetchedProperty noninheritedFetchedProperties do$>
+ .<$FetchedProperty.name$> = @"<$FetchedProperty.name$>",<$endforeach do$>
+};
+
@implementation <$managedObjectClassName$>ID
@end
Something went wrong with that request. Please try again.