Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nullability & New Attribute Objects for Objective-C Templates #317

Merged
merged 3 commits into from
Mar 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion templates/human.h.motemplate
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#import "_<$managedObjectClassName$>.h"

@interface <$managedObjectClassName$> : _<$managedObjectClassName$> {}
@interface <$managedObjectClassName$> : _<$managedObjectClassName$>
// Custom logic goes here.
@end
50 changes: 27 additions & 23 deletions templates/machine.h.motemplate
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,29 @@
#import "<$additionalHeaderFileName$>"
<$endif$>

NS_ASSUME_NONNULL_BEGIN
<$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 All @@ -53,11 +54,12 @@ extern const struct <$managedObjectClassName$>UserInfo {<$foreach UserInfo userI
* <$userInfo.discussion$>
*/
<$endif$>
@interface _<$managedObjectClassName$> : <$customSuperentity$> {}
+ (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_;

@interface _<$managedObjectClassName$> : <$customSuperentity$>
+ (instancetype)insertInManagedObjectContext:(NSManagedObjectContext *)moc_;
+ (NSString*)entityName;
+ (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_;
@property (nonatomic, readonly, strong) <$managedObjectClassName$>ID* objectID;
@property (nonatomic, readonly, strong) <$managedObjectClassName$>ID*objectID;

<$foreach Attribute noninheritedAttributes do$>
<$if Attribute.userInfo.documentation$>
Expand All @@ -69,9 +71,9 @@ extern const struct <$managedObjectClassName$>UserInfo {<$foreach UserInfo userI
<$endif$>
<$if Attribute.hasDefinedAttributeType$>
<$if Attribute.isReadonly$>
@property (nonatomic, strong, readonly) <$Attribute.objectAttributeType$> <$Attribute.name$>;
@property (nonatomic, strong, readonly<$if Attribute.optional$>, nullable<$endif$>) <$Attribute.objectAttributeType$> <$Attribute.name$>;
<$else$>
@property (nonatomic, strong) <$Attribute.objectAttributeType$> <$Attribute.name$>;
@property (nonatomic, strong<$if Attribute.optional$>, nullable<$endif$>) <$Attribute.objectAttributeType$> <$Attribute.name$>;
<$endif$>
<$if Attribute.hasScalarAttributeType$>
<$if Attribute.isReadonly$>
Expand All @@ -95,17 +97,17 @@ extern const struct <$managedObjectClassName$>UserInfo {<$foreach UserInfo userI
*/
<$endif$>
<$if Relationship.isToMany$>
@property (nonatomic, strong) <$Relationship.immutableCollectionClassName$> *<$Relationship.name$>;
- (<$Relationship.mutableCollectionClassName$>*)<$Relationship.name$>Set;
@property (nonatomic, strong<$if Relationship.optional$>, nullable<$endif$>) <$Relationship.immutableCollectionClassName$> *<$Relationship.name$>;
- (<$if Relationship.optional$>nullable <$endif$><$Relationship.mutableCollectionClassName$>*)<$Relationship.name$>Set;
<$else$>
@property (nonatomic, strong) <$Relationship.destinationEntity.managedObjectClassName$> *<$Relationship.name$>;
@property (nonatomic, strong<$if Relationship.optional$>, nullable<$endif$>) <$Relationship.destinationEntity.managedObjectClassName$> *<$Relationship.name$>;
//- (BOOL)validate<$Relationship.name.initialCapitalString$>:(id*)value_ error:(NSError**)error_;
<$endif$>
<$endforeach do$>
<$foreach FetchRequest prettyFetchRequests do$>
<$if FetchRequest.singleResult$>
+ (id)fetch<$FetchRequest.name.initialCapitalString$>:(NSManagedObjectContext*)moc_ <$foreach Binding FetchRequest.bindings do2$><$Binding.name$>:(<$Binding.type$>)<$Binding.name$>_ <$endforeach do2$>;
+ (id)fetch<$FetchRequest.name.initialCapitalString$>:(NSManagedObjectContext*)moc_ <$foreach Binding FetchRequest.bindings do2$><$Binding.name$>:(<$Binding.type$>)<$Binding.name$>_ <$endforeach do2$>error:(NSError**)error_;
+ (instancetype)fetch<$FetchRequest.name.initialCapitalString$>:(NSManagedObjectContext*)moc_ <$foreach Binding FetchRequest.bindings do2$><$Binding.name$>:(<$Binding.type$>)<$Binding.name$>_ <$endforeach do2$>;
+ (instancetype)fetch<$FetchRequest.name.initialCapitalString$>:(NSManagedObjectContext*)moc_ <$foreach Binding FetchRequest.bindings do2$><$Binding.name$>:(<$Binding.type$>)<$Binding.name$>_ <$endforeach do2$>error:(NSError**)error_;
<$else$>
+ (NSArray*)fetch<$FetchRequest.name.initialCapitalString$>:(NSManagedObjectContext*)moc_ <$foreach Binding FetchRequest.bindings do2$><$Binding.name$>:(<$Binding.type$>)<$Binding.name$>_ <$endforeach do2$>;
+ (NSArray*)fetch<$FetchRequest.name.initialCapitalString$>:(NSManagedObjectContext*)moc_ <$foreach Binding FetchRequest.bindings do2$><$Binding.name$>:(<$Binding.type$>)<$Binding.name$>_ <$endforeach do2$>error:(NSError**)error_;
Expand All @@ -119,7 +121,7 @@ extern const struct <$managedObjectClassName$>UserInfo {<$foreach UserInfo userI
* <$FetchedProperty.userInfo.discussion$>
*/
<$endif$>
@property (nonatomic, readonly) NSArray *<$FetchedProperty.name$>;
@property (nonatomic, readonly<$if FetchedProperty.optional$>, nullable<$endif$>) NSArray *<$FetchedProperty.name$>;
<$endforeach do$>
<$if TemplateVar.frc$>
#if TARGET_OS_IPHONE
Expand All @@ -132,6 +134,7 @@ extern const struct <$managedObjectClassName$>UserInfo {<$foreach UserInfo userI
<$endif$>
@end


<$foreach Relationship noninheritedRelationships do$>
<$if Relationship.isToMany$>
@interface _<$managedObjectClassName$> (<$Relationship.name.initialCapitalString$>CoreDataGeneratedAccessors)
Expand Down Expand Up @@ -172,3 +175,4 @@ extern const struct <$managedObjectClassName$>UserInfo {<$foreach UserInfo userI
<$endif$>
<$endforeach do$>
@end
NS_ASSUME_NONNULL_END
38 changes: 23 additions & 15 deletions templates/machine.m.motemplate
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,43 @@
#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
@end

@implementation _<$managedObjectClassName$>

+ (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_ {
+ (instancetype)insertInManagedObjectContext:(NSManagedObjectContext *)moc_ {
NSParameterAssert(moc_);
return [NSEntityDescription insertNewObjectForEntityForName:@"<$name$>" inManagedObjectContext:moc_];
}
Expand Down Expand Up @@ -117,7 +125,7 @@ const struct <$managedObjectClassName$>UserInfo <$managedObjectClassName$>UserIn

<$foreach FetchRequest prettyFetchRequests do$>
<$if FetchRequest.singleResult$>
+ (id)fetch<$FetchRequest.name.initialCapitalString$>:(NSManagedObjectContext*)moc_ <$foreach Binding FetchRequest.bindings do2$><$Binding.name$>:(<$Binding.type$>)<$Binding.name$>_ <$endforeach do2$>{
+ (instancetype)fetch<$FetchRequest.name.initialCapitalString$>:(NSManagedObjectContext*)moc_ <$foreach Binding FetchRequest.bindings do2$><$Binding.name$>:(<$Binding.type$>)<$Binding.name$>_ <$endforeach do2$>{
NSError *error = nil;
id result = [self fetch<$FetchRequest.name.initialCapitalString$>:moc_ <$foreach Binding FetchRequest.bindings do2$><$Binding.name$>:<$Binding.name$>_ <$endforeach do2$>error:&error];
if (error) {
Expand All @@ -129,7 +137,7 @@ const struct <$managedObjectClassName$>UserInfo <$managedObjectClassName$>UserIn
}
return result;
}
+ (id)fetch<$FetchRequest.name.initialCapitalString$>:(NSManagedObjectContext*)moc_ <$foreach Binding FetchRequest.bindings do2$><$Binding.name$>:(<$Binding.type$>)<$Binding.name$>_ <$endforeach do2$>error:(NSError**)error_ {
+ (instancetype)fetch<$FetchRequest.name.initialCapitalString$>:(NSManagedObjectContext*)moc_ <$foreach Binding FetchRequest.bindings do2$><$Binding.name$>:(<$Binding.type$>)<$Binding.name$>_ <$endforeach do2$>error:(NSError**)error_ {
NSParameterAssert(moc_);
NSError *error = nil;

Expand Down