Skip to content

Commit

Permalink
Add entity level “additionalImports”, a comma-separated list of modul…
Browse files Browse the repository at this point in the history
…es to import.
  • Loading branch information
atomicbird committed Aug 9, 2018
1 parent 0a39417 commit aaea23b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions mogenerator.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

static const NSString *const kAttributeValueScalarTypeKey = @"attributeValueScalarType";
static const NSString *const kAdditionalHeaderFileNameKey = @"additionalHeaderFileName";
static const NSString *const kAdditionalImportsKey = @"additionalImports";
static const NSString *const kCustomBaseClass = @"mogenerator.customBaseClass";
static const NSString *const kReadOnly = @"mogenerator.readonly";

Expand Down Expand Up @@ -183,6 +184,10 @@ - (BOOL)hasAdditionalHeaderFile {
return [[[self userInfo] allKeys] containsObject:kAdditionalHeaderFileNameKey];
}

- (BOOL)hasAdditionalImports {
return [[[self userInfo] allKeys] containsObject:kAdditionalImportsKey];
}

- (NSString*)customSuperentity {
NSString *forcedBaseClass = [self forcedCustomBaseClass];
if (!forcedBaseClass) {
Expand Down Expand Up @@ -222,6 +227,15 @@ - (NSString*)additionalHeaderFileName {
return [[self userInfo] objectForKey:kAdditionalHeaderFileNameKey];
}

- (NSArray *)additionalImports {
NSString *csvString = [[self userInfo] objectForKey:kAdditionalImportsKey];
NSMutableArray *imports = [[csvString componentsSeparatedByString:@","] mutableCopy];
[imports enumerateObjectsUsingBlock:^(NSString *import, NSUInteger idx, BOOL * _Nonnull stop) {
imports[idx] = [import stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet];
}];
return imports;
}

/** @TypeInfo NSAttributeDescription */
- (NSArray*)noninheritedAttributesSansType {
NSArray *attributeDescriptions = [self noninheritedAttributes];
Expand Down
6 changes: 6 additions & 0 deletions templates/machine.h.motemplate
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
#import "<$additionalHeaderFileName$>"
<$endif$>

<$if hasAdditionalImports$>
<$foreach Import additionalImports do$>
@import <$Import$>;
<$endforeach do$>
<$endif$>

NS_ASSUME_NONNULL_BEGIN

<$foreach Relationship noninheritedRelationships do$>@class <$Relationship.destinationEntity.managedObjectClassName$>;
Expand Down
6 changes: 6 additions & 0 deletions templates/machine.swift.motemplate
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import Foundation
import CoreData
<$if hasCustomBaseCaseImport$>import <$baseClassImport$><$endif$>

<$if hasAdditionalImports$>
<$foreach Import additionalImports do$>
import <$Import$>
<$endforeach do$>
<$endif$>

<$if noninheritedAttributes.@count > 0$>
public enum <$sanitizedManagedObjectClassName$>Attributes: String {<$foreach Attribute noninheritedAttributes do$>
case <$Attribute.name$> = "<$Attribute.name$>"<$endforeach do$>
Expand Down

0 comments on commit aaea23b

Please sign in to comment.