diff --git a/mogenerator.h b/mogenerator.h index 586d0ffb..855c28d2 100644 --- a/mogenerator.h +++ b/mogenerator.h @@ -19,6 +19,7 @@ @end @interface NSEntityDescription (customBaseClass) +- (BOOL)hasCustomClass; - (BOOL)hasSuperentity; - (BOOL)hasCustomSuperentity; - (NSString*)customSuperentity; diff --git a/mogenerator.m b/mogenerator.m index f6d996c9..e56c1872 100644 --- a/mogenerator.m +++ b/mogenerator.m @@ -54,13 +54,13 @@ - (NSArray*)entitiesWithACustomSubclassInConfiguration:(NSString*)configuration_ nsenumerate (allEntities, NSEntityDescription, entity) { NSString *entityClassName = [entity managedObjectClassName]; - if ([entityClassName isEqualToString:@"NSManagedObject"] || [entityClassName isEqualToString:@""] || [entityClassName isEqualToString:gCustomBaseClass]){ + if ([entity hasCustomClass]){ + [result addObject:entity]; + } else { if (verbose_) { ddprintf(@"skipping entity %@ (%@) because it doesn't use a custom subclass.\n", entity.name, entityClassName); } - } else { - [result addObject:entity]; } } @@ -77,6 +77,15 @@ - (BOOL)hasCustomBaseCaseImport { - (NSString*)baseClassImport { return gCustomBaseClassImport; } + +- (BOOL)hasCustomClass { + NSString *entityClassName = [self managedObjectClassName]; + BOOL result = !([entityClassName isEqualToString:@"NSManagedObject"] + || [entityClassName isEqualToString:@""] + || [entityClassName isEqualToString:gCustomBaseClass]); + return result; +} + - (BOOL)hasSuperentity { NSEntityDescription *superentity = [self superentity]; if (superentity) { @@ -90,7 +99,7 @@ - (BOOL)hasCustomSuperentity { if (!forcedBaseClass) { NSEntityDescription *superentity = [self superentity]; if (superentity) { - return YES; + return [superentity hasCustomClass] ? YES : NO; } else { return gCustomBaseClass ? YES : NO; } @@ -98,6 +107,7 @@ - (BOOL)hasCustomSuperentity { return YES; } } + - (NSString*)customSuperentity { NSString *forcedBaseClass = [self forcedCustomBaseClass]; if (!forcedBaseClass) { @@ -969,13 +979,13 @@ - (int)application:(DDCliApplication*)app runWithArguments:(NSArray*)arguments { [fm removeItemAtPath:tempGeneratedMomFilePath error:nil]; } bool mfileGenerated = NO; - if (mfilePath && ![mfileContent isEqualToString:@""]) { + if (mfilePath && ![mfileContent isEqualToString:@""] && (![fm regularFileExistsAtPath:mfilePath] || ![[NSString stringWithContentsOfFile:mfilePath encoding:NSUTF8StringEncoding error:nil] isEqualToString:mfileContent])) { [mfileContent writeToFile:mfilePath atomically:NO encoding:NSUTF8StringEncoding error:nil]; mfileGenerated = YES; } bool hfileGenerated = NO; - if (hfilePath && ![hfileContent isEqualToString:@""]) { + if (hfilePath && ![hfileContent isEqualToString:@""] && (![fm regularFileExistsAtPath:hfilePath] || ![[NSString stringWithContentsOfFile:hfilePath encoding:NSUTF8StringEncoding error:nil] isEqualToString:hfileContent])) { [hfileContent writeToFile:hfilePath atomically:NO encoding:NSUTF8StringEncoding error:nil]; hfileGenerated = YES; } diff --git a/test/test.xcdatamodel/elements b/test/test.xcdatamodel/elements index 7b917736..f04b7e82 100644 Binary files a/test/test.xcdatamodel/elements and b/test/test.xcdatamodel/elements differ diff --git a/test/test.xcdatamodel/layout b/test/test.xcdatamodel/layout index 80ea6d65..5675d1b3 100644 Binary files a/test/test.xcdatamodel/layout and b/test/test.xcdatamodel/layout differ