From b89f8cdfd6c505161865301976d4aaaff3e7ad58 Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Fri, 18 Oct 2024 17:55:11 -0400 Subject: [PATCH] issue #83: Added option to make Mike Ash-style classes optional No change in behaviour by default. But now if the command line includes `--template-var include-ash-classes=false` then these classes will not be created. If you don't use them, this reduces code size a bit (200 KB / 0.12 % in my case) and removes things from Xcode's autocomplete that are just clutter. --- mogenerator.m | 5 +++++ templates/machine.h.motemplate | 3 +++ templates/machine.m.motemplate | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/mogenerator.m b/mogenerator.m index e2b786fe..607959f9 100644 --- a/mogenerator.m +++ b/mogenerator.m @@ -1076,6 +1076,11 @@ - (int)application:(DDCliApplication*)app runWithArguments:(NSArray*)arguments { return EXIT_SUCCESS; } + // Default to generating Mike Ash-style classes if nothing specific was specified in the command arguments + NSNumber * useAshClassesObj = [templateVar objectForKey:@"include-ash-classes"]; + BOOL useAshClasses = !useAshClassesObj || [useAshClassesObj boolValue]; + [templateVar setObject:[NSNumber numberWithBool:useAshClasses] forKey:@"include-ash-classes"]; + gSwift = _swift; if (baseClassForce) { diff --git a/templates/machine.h.motemplate b/templates/machine.h.motemplate index 4b64aaa9..3e588f4e 100644 --- a/templates/machine.h.motemplate +++ b/templates/machine.h.motemplate @@ -171,6 +171,7 @@ NS_ASSUME_NONNULL_BEGIN <$endforeach do$> @end +<$if TemplateVar.include-ash-classes$> <$if noninheritedAttributes.@count > 0$> @interface <$managedObjectClassName$>Attributes: NSObject <$foreach Attribute noninheritedAttributes do$> @@ -196,4 +197,6 @@ NS_ASSUME_NONNULL_BEGIN @end <$endif$> +<$endif$> + NS_ASSUME_NONNULL_END diff --git a/templates/machine.m.motemplate b/templates/machine.m.motemplate index 70129f2c..45282c99 100644 --- a/templates/machine.m.motemplate +++ b/templates/machine.m.motemplate @@ -277,6 +277,8 @@ @end <$endif$><$endif$><$endforeach do$> +<$if TemplateVar.include-ash-classes$> + <$if noninheritedAttributes.@count > 0$> @implementation <$managedObjectClassName$>Attributes <$foreach Attribute noninheritedAttributes do$> + (NSString *)<$Attribute.name$> { @@ -308,3 +310,5 @@ }<$endforeach do$> @end <$endif$> + +<$endif$>