Skip to content

Commit

Permalink
Specifically suppress setPrimitiveType: generation -- apparently it t…
Browse files Browse the repository at this point in the history
…riggers Apple's piss-poor private-API-use detector when submitting to the App Store. Closes #16.
  • Loading branch information
rentzsch committed Jan 14, 2013
1 parent 9758e61 commit cd9809d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions mogenerator.m
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,18 @@ - (NSArray*)noninheritedAttributes {
}
}
/** @TypeInfo NSAttributeDescription */
- (NSArray*)noninheritedAttributesSansType {
NSArray *attributeDescriptions = [self noninheritedAttributes];
NSMutableArray *filteredAttributeDescriptions = [NSMutableArray arrayWithCapacity:[attributeDescriptions count]];

nsenumerate(attributeDescriptions, NSAttributeDescription, attributeDescription) {
if (![[attributeDescription name] isEqualToString:@"type"]) {
[filteredAttributeDescriptions addObject:attributeDescription];
}
}
return filteredAttributeDescriptions;
}
/** @TypeInfo NSAttributeDescription */
- (NSArray*)noninheritedRelationships {
NSArray *sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES]];
NSEntityDescription *superentity = [self superentity];
Expand Down
2 changes: 1 addition & 1 deletion templates/machine.h.motemplate
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ extern const struct <$managedObjectClassName$>FetchedProperties {<$foreach Fetch
<$endif$><$endforeach do$>

@interface _<$managedObjectClassName$> (CoreDataGeneratedPrimitiveAccessors)
<$foreach Attribute noninheritedAttributes do$>
<$foreach Attribute noninheritedAttributesSansType do$>
<$if Attribute.hasDefinedAttributeType$>
- (<$Attribute.objectAttributeType$>)primitive<$Attribute.name.initialCapitalString$>;
- (void)setPrimitive<$Attribute.name.initialCapitalString$>:(<$Attribute.objectAttributeType$>)value;
Expand Down
Binary file modified test/test.xcdatamodel/elements
Binary file not shown.
Binary file modified test/test.xcdatamodel/layout
Binary file not shown.

6 comments on commit cd9809d

@danielctull
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @rentzsch, this change has seemingly broken things for me when using attributes of Integer type.

The machine implementation includes these methods (where I have an intAttribute attribute) which is causing Xcode to throw an error about primitiveIntAttribute and setPrimitiveIntAttribute not existing.

- (int16_t)primitiveIntAttributeValue {
    NSNumber *result = [self primitiveIntAttribute];
    return [result shortValue];
}

- (void)setPrimitiveIntAttributeValue:(int16_t)value_ {
    [self setPrimitiveIntAttribute:[NSNumber numberWithShort:value_]];
}

Changing back to use noninheritedAttributes puts the method declarations back and obviously fixes things. Though, if Apple have problems with it… :-/

@rentzsch
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I'm not understanding the problem, or at least I can't reproduce it in the Test Dir. This work-around should only deal with attributes named "type" and "intAttribute" surely doesn't match that.

Can you repro the issue with the Test Dir?

@danielctull
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! I think I've been stupid, I'm still running the last version of mogenerator using the updated templates, my bad. :-/

@rentzsch
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, it can be problematic keeping them in sync. Hence why the default templates are built into the binary itself nowadays.

@KiGi
Copy link

@KiGi KiGi commented on cd9809d Sep 10, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a quick way to get to the version of templates that ship with the current binary? I copied the templates out of GitHub to make some changes and ran into the same issue, and them came across these commit notes when I figured out what the issue was... I'd like to make sure changes I make are only against templates that match the shipping binaries so others can use them with the shipping version of mogenerator.

@danielctull
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @KiGi, the best way in my mind would be to clone the repository and checkout the 1.27 tag. Once this is checked out, you can make a branch to work on and modify the templates. When a new version of mogenerator is released, you can then merge it into your branch and this will allow your modified template to get the updates that have been made since 1.27. Hope this helps.

Please sign in to comment.