Skip to content

Commit

Permalink
Add a new check to see if an entity has a custom class and also has a…
Browse files Browse the repository at this point in the history
… superentity with a custom class, to handle Swift rules for including "override" in method declarations.
  • Loading branch information
atomicbird committed Apr 30, 2015
1 parent fc99ca4 commit 6f57408
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions mogenerator.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
4 changes: 2 additions & 2 deletions templates/machine.swift.motemplate
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 6f57408

Please sign in to comment.