Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add constant structs for the property names #72

Merged
merged 1 commit into from

4 participants

Daniel Tull extremeboredom Jonathan 'Wolf' Rentzsch Jean-Denis Muys
Daniel Tull

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.

Daniel Tull 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.

Daniel Tull

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!)

Jonathan 'Wolf' Rentzsch rentzsch merged commit 778bf54 into from
Jonathan 'Wolf' Rentzsch
Owner

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

Jean-Denis Muys

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

Daniel Tull

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

Jonathan 'Wolf' 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. Daniel Tull

    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
12 templates/machine.h.motemplate
View
@@ -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$>
12 templates/machine.m.motemplate
View
@@ -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.