Skip to content

Commit

Permalink
Switch out structs with __unsafe_unretained NSString * objects for at…
Browse files Browse the repository at this point in the history
…tribute/relationship/etc keys in favor of full on NSObject subclasses. ARC, baby!
  • Loading branch information
justin committed Mar 3, 2016
1 parent 47db28b commit 69eb701
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
24 changes: 12 additions & 12 deletions templates/machine.h.motemplate
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@
<$endif$>

<$if noninheritedAttributes.@count > 0$>
extern const struct <$managedObjectClassName$>Attributes {<$foreach Attribute noninheritedAttributes do$>
__unsafe_unretained NSString *<$Attribute.name$>;<$endforeach do$>
} <$managedObjectClassName$>Attributes;
@interface <$managedObjectClassName$>Attributes: NSObject <$foreach Attribute noninheritedAttributes do$>
+ (NSString *)<$Attribute.name$>;<$endforeach do$>
@end
<$endif$>

<$if noninheritedRelationships.@count > 0$>
extern const struct <$managedObjectClassName$>Relationships {<$foreach Relationship noninheritedRelationships do$>
__unsafe_unretained NSString *<$Relationship.name$>;<$endforeach do$>
} <$managedObjectClassName$>Relationships;
@interface <$managedObjectClassName$>Relationships: NSObject<$foreach Relationship noninheritedRelationships do$>
+ (NSString *)<$Relationship.name$>;<$endforeach do$>
@end
<$endif$>

<$if noninheritedFetchedProperties.@count > 0$>
extern const struct <$managedObjectClassName$>FetchedProperties {<$foreach FetchedProperty noninheritedFetchedProperties do$>
__unsafe_unretained NSString *<$FetchedProperty.name$>;<$endforeach do$>
} <$managedObjectClassName$>FetchedProperties;
@interface <$managedObjectClassName$>FetchedProperties: NSObject<$foreach FetchedProperty noninheritedFetchedProperties do$>
+ (NSString *)<$FetchedProperty.name$>;<$endforeach do$>
@end
<$endif$>

<$if hasUserInfoKeys$>
extern const struct <$managedObjectClassName$>UserInfo {<$foreach UserInfo userInfoKeyValues do$>
__unsafe_unretained NSString *<$UserInfo.key$>;<$endforeach do$>
} <$managedObjectClassName$>UserInfo;
@interface <$managedObjectClassName$>UserInfo: NSObject <$foreach UserInfo userInfoKeyValues do$>
+ (NSString *)<$UserInfo.key$>;<$endforeach do$>
@end
<$endif$>

<$foreach Relationship noninheritedRelationships do$>@class <$Relationship.destinationEntity.managedObjectClassName$>;
Expand Down
32 changes: 20 additions & 12 deletions templates/machine.m.motemplate
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,35 @@
#import "_<$managedObjectClassName$>.h"

<$if noninheritedAttributes.@count > 0$>
const struct <$managedObjectClassName$>Attributes <$managedObjectClassName$>Attributes = {<$foreach Attribute noninheritedAttributes do$>
.<$Attribute.name$> = @"<$Attribute.name$>",<$endforeach do$>
};
@implementation <$managedObjectClassName$>Attributes <$foreach Attribute noninheritedAttributes do$>
+ (NSString *)<$Attribute.name$> {
return @"<$Attribute.name$>";
}<$endforeach do$>
@end
<$endif$>

<$if noninheritedRelationships.@count > 0$>
const struct <$managedObjectClassName$>Relationships <$managedObjectClassName$>Relationships = {<$foreach Relationship noninheritedRelationships do$>
.<$Relationship.name$> = @"<$Relationship.name$>",<$endforeach do$>
};
@implementation <$managedObjectClassName$>Relationships <$foreach Relationship noninheritedRelationships do$>
+ (NSString *)<$Relationship.name$> {
return @"<$Relationship.name$>";
}<$endforeach do$>
@end
<$endif$>

<$if noninheritedFetchedProperties.@count > 0$>
const struct <$managedObjectClassName$>FetchedProperties <$managedObjectClassName$>FetchedProperties = {<$foreach FetchedProperty noninheritedFetchedProperties do$>
.<$FetchedProperty.name$> = @"<$FetchedProperty.name$>",<$endforeach do$>
};
@implementation <$managedObjectClassName$>FetchedProperties <$foreach FetchedProperty noninheritedFetchedProperties do$>
+ (NSString *)<$FetchedProperty.name$> {
return @"<$FetchedProperty.name$>";
}<$endforeach do$>
@end
<$endif$>

<$if hasUserInfoKeys$>
const struct <$managedObjectClassName$>UserInfo <$managedObjectClassName$>UserInfo = {<$foreach UserInfo userInfoKeyValues do$>
.<$UserInfo.key$> = @"<$UserInfo.value$>",<$endforeach do$>
};
@implementation <$managedObjectClassName$>UserInfo <$foreach UserInfo userInfoKeyValues do$>
+ (NSString *)<$UserInfo.key$> {
return @"<$UserInfo.value$>";
}<$endforeach do$>
@end
<$endif$>

@implementation <$managedObjectClassName$>ID
Expand Down

0 comments on commit 69eb701

Please sign in to comment.