diff --git a/mogenerator.m b/mogenerator.m index f383c7ff..241621cf 100644 --- a/mogenerator.m +++ b/mogenerator.m @@ -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"; @@ -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) { @@ -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]; diff --git a/templates/machine.h.motemplate b/templates/machine.h.motemplate index 66cb54bb..4b64aaa9 100644 --- a/templates/machine.h.motemplate +++ b/templates/machine.h.motemplate @@ -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$>; diff --git a/templates/machine.swift.motemplate b/templates/machine.swift.motemplate index 20010154..f423728e 100644 --- a/templates/machine.swift.motemplate +++ b/templates/machine.swift.motemplate @@ -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$>