Skip to content

Commit b12d7a4

Browse files
committed
Nullability attributes for Objective-C machine templates
1 parent 83f031d commit b12d7a4

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

templates/human.h.motemplate

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#import "_<$managedObjectClassName$>.h"
22

3-
@interface <$managedObjectClassName$> : _<$managedObjectClassName$> {}
3+
@interface <$managedObjectClassName$> : _<$managedObjectClassName$>
44
// Custom logic goes here.
55
@end

templates/machine.h.motemplate

+11-7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#import "<$additionalHeaderFileName$>"
1111
<$endif$>
1212

13+
NS_ASSUME_NONNULL_BEGIN
1314
<$if noninheritedAttributes.@count > 0$>
1415
@interface <$managedObjectClassName$>Attributes: NSObject <$foreach Attribute noninheritedAttributes do$>
1516
+ (NSString *)<$Attribute.name$>;<$endforeach do$>
@@ -53,11 +54,12 @@
5354
* <$userInfo.discussion$>
5455
*/
5556
<$endif$>
57+
5658
@interface _<$managedObjectClassName$> : <$customSuperentity$>
5759
+ (instancetype)insertInManagedObjectContext:(NSManagedObjectContext *)moc_;
5860
+ (NSString*)entityName;
5961
+ (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_;
60-
@property (nonatomic, readonly, strong) <$managedObjectClassName$>ID* objectID;
62+
@property (nonatomic, readonly, strong) <$managedObjectClassName$>ID*objectID;
6163

6264
<$foreach Attribute noninheritedAttributes do$>
6365
<$if Attribute.userInfo.documentation$>
@@ -69,9 +71,9 @@
6971
<$endif$>
7072
<$if Attribute.hasDefinedAttributeType$>
7173
<$if Attribute.isReadonly$>
72-
@property (nonatomic, strong, readonly) <$Attribute.objectAttributeType$> <$Attribute.name$>;
74+
@property (nonatomic, strong, readonly<$if Attribute.optional$>, nullable<$endif$>) <$Attribute.objectAttributeType$> <$Attribute.name$>;
7375
<$else$>
74-
@property (nonatomic, strong) <$Attribute.objectAttributeType$> <$Attribute.name$>;
76+
@property (nonatomic, strong<$if Attribute.optional$>, nullable<$endif$>) <$Attribute.objectAttributeType$> <$Attribute.name$>;
7577
<$endif$>
7678
<$if Attribute.hasScalarAttributeType$>
7779
<$if Attribute.isReadonly$>
@@ -95,10 +97,10 @@
9597
*/
9698
<$endif$>
9799
<$if Relationship.isToMany$>
98-
@property (nonatomic, strong) <$Relationship.immutableCollectionClassName$> *<$Relationship.name$>;
99-
- (<$Relationship.mutableCollectionClassName$>*)<$Relationship.name$>Set;
100+
@property (nonatomic, strong<$if Relationship.optional$>, nullable<$endif$>) <$Relationship.immutableCollectionClassName$> *<$Relationship.name$>;
101+
- (<$if Relationship.optional$>nullable <$endif$><$Relationship.mutableCollectionClassName$>*)<$Relationship.name$>Set;
100102
<$else$>
101-
@property (nonatomic, strong) <$Relationship.destinationEntity.managedObjectClassName$> *<$Relationship.name$>;
103+
@property (nonatomic, strong<$if Relationship.optional$>, nullable<$endif$>) <$Relationship.destinationEntity.managedObjectClassName$> *<$Relationship.name$>;
102104
//- (BOOL)validate<$Relationship.name.initialCapitalString$>:(id*)value_ error:(NSError**)error_;
103105
<$endif$>
104106
<$endforeach do$>
@@ -119,7 +121,7 @@
119121
* <$FetchedProperty.userInfo.discussion$>
120122
*/
121123
<$endif$>
122-
@property (nonatomic, readonly) NSArray *<$FetchedProperty.name$>;
124+
@property (nonatomic, readonly<$if FetchedProperty.optional$>, nullable<$endif$>) NSArray *<$FetchedProperty.name$>;
123125
<$endforeach do$>
124126
<$if TemplateVar.frc$>
125127
#if TARGET_OS_IPHONE
@@ -132,6 +134,7 @@
132134
<$endif$>
133135
@end
134136

137+
135138
<$foreach Relationship noninheritedRelationships do$>
136139
<$if Relationship.isToMany$>
137140
@interface _<$managedObjectClassName$> (<$Relationship.name.initialCapitalString$>CoreDataGeneratedAccessors)
@@ -172,3 +175,4 @@
172175
<$endif$>
173176
<$endforeach do$>
174177
@end
178+
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)