Skip to content
This repository

Add constant structs for the property names #72

Merged
merged 1 commit into from over 2 years ago

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 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 August 30, 2011
Jonathan 'Wolf' Rentzsch rentzsch closed this August 30, 2011
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

Showing 1 unique commit by 1 author.

Aug 30, 2011
Daniel Tull 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
This page is out of date. Refresh to see the latest.
12  templates/machine.h.motemplate
@@ -4,6 +4,18 @@
4 4
 #import <CoreData/CoreData.h>
5 5
 <$if hasCustomSuperentity$>#import "<$customSuperentity$>.h"<$endif$>
6 6
 
  7
+extern const struct <$managedObjectClassName$>Attributes {<$foreach Attribute noninheritedAttributes do$>
  8
+	<$if TemplateVar.arc$>__unsafe_unretained<$endif$> NSString *<$Attribute.name$>;<$endforeach do$>
  9
+} <$managedObjectClassName$>Attributes;
  10
+
  11
+extern const struct <$managedObjectClassName$>Relationships {<$foreach Relationship noninheritedRelationships do$>
  12
+	<$if TemplateVar.arc$>__unsafe_unretained<$endif$> NSString *<$Relationship.name$>;<$endforeach do$>
  13
+} <$managedObjectClassName$>Relationships;
  14
+
  15
+extern const struct <$managedObjectClassName$>FetchedProperties {<$foreach FetchedProperty noninheritedFetchedProperties do$>
  16
+	<$if TemplateVar.arc$>__unsafe_unretained<$endif$> NSString *<$FetchedProperty.name$>;<$endforeach do$>
  17
+} <$managedObjectClassName$>FetchedProperties;
  18
+
7 19
 <$foreach Relationship noninheritedRelationships do$>@class <$Relationship.destinationEntity.managedObjectClassName$>;
8 20
 <$endforeach do$>
9 21
 <$foreach Attribute noninheritedAttributes do$><$if Attribute.hasTransformableAttributeType$>@class <$Attribute.objectAttributeType$>;<$endif$>
12  templates/machine.m.motemplate
@@ -3,6 +3,18 @@
3 3
 
4 4
 #import "_<$managedObjectClassName$>.h"
5 5
 
  6
+const struct <$managedObjectClassName$>Attributes <$managedObjectClassName$>Attributes = {<$foreach Attribute noninheritedAttributes do$>
  7
+	.<$Attribute.name$> = @"<$Attribute.name$>",<$endforeach do$>
  8
+};
  9
+
  10
+const struct <$managedObjectClassName$>Relationships <$managedObjectClassName$>Relationships = {<$foreach Relationship noninheritedRelationships do$>
  11
+	.<$Relationship.name$> = @"<$Relationship.name$>",<$endforeach do$>
  12
+};
  13
+
  14
+const struct <$managedObjectClassName$>FetchedProperties <$managedObjectClassName$>FetchedProperties = {<$foreach FetchedProperty noninheritedFetchedProperties do$>
  15
+	.<$FetchedProperty.name$> = @"<$FetchedProperty.name$>",<$endforeach do$>
  16
+};
  17
+
6 18
 @implementation <$managedObjectClassName$>ID
7 19
 @end
8 20
 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.