Skip to content

Commit 69eb701

Browse files
committed
Switch out structs with __unsafe_unretained NSString * objects for attribute/relationship/etc keys in favor of full on NSObject subclasses. ARC, baby!
1 parent 47db28b commit 69eb701

File tree

2 files changed

+32
-24
lines changed

2 files changed

+32
-24
lines changed

templates/machine.h.motemplate

+12-12
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,27 @@
1111
<$endif$>
1212

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

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

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

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

3737
<$foreach Relationship noninheritedRelationships do$>@class <$Relationship.destinationEntity.managedObjectClassName$>;

templates/machine.m.motemplate

+20-12
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,35 @@
44
#import "_<$managedObjectClassName$>.h"
55

66
<$if noninheritedAttributes.@count > 0$>
7-
const struct <$managedObjectClassName$>Attributes <$managedObjectClassName$>Attributes = {<$foreach Attribute noninheritedAttributes do$>
8-
.<$Attribute.name$> = @"<$Attribute.name$>",<$endforeach do$>
9-
};
7+
@implementation <$managedObjectClassName$>Attributes <$foreach Attribute noninheritedAttributes do$>
8+
+ (NSString *)<$Attribute.name$> {
9+
return @"<$Attribute.name$>";
10+
}<$endforeach do$>
11+
@end
1012
<$endif$>
1113

1214
<$if noninheritedRelationships.@count > 0$>
13-
const struct <$managedObjectClassName$>Relationships <$managedObjectClassName$>Relationships = {<$foreach Relationship noninheritedRelationships do$>
14-
.<$Relationship.name$> = @"<$Relationship.name$>",<$endforeach do$>
15-
};
15+
@implementation <$managedObjectClassName$>Relationships <$foreach Relationship noninheritedRelationships do$>
16+
+ (NSString *)<$Relationship.name$> {
17+
return @"<$Relationship.name$>";
18+
}<$endforeach do$>
19+
@end
1620
<$endif$>
1721

1822
<$if noninheritedFetchedProperties.@count > 0$>
19-
const struct <$managedObjectClassName$>FetchedProperties <$managedObjectClassName$>FetchedProperties = {<$foreach FetchedProperty noninheritedFetchedProperties do$>
20-
.<$FetchedProperty.name$> = @"<$FetchedProperty.name$>",<$endforeach do$>
21-
};
23+
@implementation <$managedObjectClassName$>FetchedProperties <$foreach FetchedProperty noninheritedFetchedProperties do$>
24+
+ (NSString *)<$FetchedProperty.name$> {
25+
return @"<$FetchedProperty.name$>";
26+
}<$endforeach do$>
27+
@end
2228
<$endif$>
2329

2430
<$if hasUserInfoKeys$>
25-
const struct <$managedObjectClassName$>UserInfo <$managedObjectClassName$>UserInfo = {<$foreach UserInfo userInfoKeyValues do$>
26-
.<$UserInfo.key$> = @"<$UserInfo.value$>",<$endforeach do$>
27-
};
31+
@implementation <$managedObjectClassName$>UserInfo <$foreach UserInfo userInfoKeyValues do$>
32+
+ (NSString *)<$UserInfo.key$> {
33+
return @"<$UserInfo.value$>";
34+
}<$endforeach do$>
35+
@end
2836
<$endif$>
2937

3038
@implementation <$managedObjectClassName$>ID

0 commit comments

Comments
 (0)