From 6f57408e7a1db0ebd07fb8a8190f819082293014 Mon Sep 17 00:00:00 2001 From: Tom Harrington Date: Thu, 30 Apr 2015 15:50:42 -0600 Subject: [PATCH] Add a new check to see if an entity has a custom class and also has a superentity with a custom class, to handle Swift rules for including "override" in method declarations. --- mogenerator.m | 6 ++++++ templates/machine.swift.motemplate | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/mogenerator.m b/mogenerator.m index 4a6b819e..4c6ab607 100644 --- a/mogenerator.m +++ b/mogenerator.m @@ -151,6 +151,12 @@ - (BOOL)hasCustomSuperentity { } } +- (BOOL)hasCustomSuperclass { + // For Swift, where "override" is needed when both the entity and its superentity have custom classes. + BOOL result = [self hasCustomClass] && [self hasCustomSuperentity] && [[self superentity] hasCustomClass]; + return result; +} + - (BOOL)hasAdditionalHeaderFile { return [[[self userInfo] allKeys] containsObject:kAdditionalHeaderFileNameKey]; } diff --git a/templates/machine.swift.motemplate b/templates/machine.swift.motemplate index 4189bc4d..409eea6c 100644 --- a/templates/machine.swift.motemplate +++ b/templates/machine.swift.motemplate @@ -34,11 +34,11 @@ class _<$managedObjectClassName$>: <$customSuperentity$> { // MARK: - Class methods - <$if hasCustomSuperentity$>override <$endif$>public class func entityName () -> String { + <$if hasCustomSuperclass$>override <$endif$>public class func entityName () -> String { return "<$name$>" } - <$if hasCustomSuperentity$>override <$endif$>public class func entity(managedObjectContext: NSManagedObjectContext!) -> NSEntityDescription! { + <$if hasCustomSuperclass$>override <$endif$>public class func entity(managedObjectContext: NSManagedObjectContext!) -> NSEntityDescription! { return NSEntityDescription.entityForName(self.entityName(), inManagedObjectContext: managedObjectContext); }