From 84abc62ba5e2a11ffc4f483e6ff4fe2664481e23 Mon Sep 17 00:00:00 2001 From: John Clayton Date: Mon, 1 Apr 2019 18:00:16 -0400 Subject: [PATCH 1/3] This commit fixes #339. Check for empty module name (leading '.') and remove it from the representedClasName. --- momcom/NSEntityDescription+momcom.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/momcom/NSEntityDescription+momcom.m b/momcom/NSEntityDescription+momcom.m index 662883e7..3e8c332a 100644 --- a/momcom/NSEntityDescription+momcom.m +++ b/momcom/NSEntityDescription+momcom.m @@ -28,6 +28,9 @@ + (NSEntityDescription *)baseEntityForXML:(NSXMLElement *)xmlNode if ([attributeName isEqualToString:@"name"]) { [entityDescription setName:attributeString]; } else if ([attributeName isEqualToString:@"representedClassName"]) { + if ([attributeString hasPrefix:@"."]) { + attributeString = [attributeString substringFromIndex:1]; + } [entityDescription setManagedObjectClassName:attributeString]; } else if ([attributeName isEqualToString:@"elementID"]) { [entityDescription setRenamingIdentifier:attributeString]; From 21e355748d03ec70d9047b10216e0a3d1b5c7df9 Mon Sep 17 00:00:00 2001 From: John Clayton Date: Mon, 1 Apr 2019 18:09:20 -0400 Subject: [PATCH 2/3] Replaced tabs with spaces for the fix to #339 --- momcom/NSEntityDescription+momcom.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/momcom/NSEntityDescription+momcom.m b/momcom/NSEntityDescription+momcom.m index 3e8c332a..5fbdbfec 100644 --- a/momcom/NSEntityDescription+momcom.m +++ b/momcom/NSEntityDescription+momcom.m @@ -28,9 +28,9 @@ + (NSEntityDescription *)baseEntityForXML:(NSXMLElement *)xmlNode if ([attributeName isEqualToString:@"name"]) { [entityDescription setName:attributeString]; } else if ([attributeName isEqualToString:@"representedClassName"]) { - if ([attributeString hasPrefix:@"."]) { - attributeString = [attributeString substringFromIndex:1]; - } + if ([attributeString hasPrefix:@"."]) { + attributeString = [attributeString substringFromIndex:1]; + } [entityDescription setManagedObjectClassName:attributeString]; } else if ([attributeName isEqualToString:@"elementID"]) { [entityDescription setRenamingIdentifier:attributeString]; From fc0fb14cc29a28aad01724786764a9370c6f038d Mon Sep 17 00:00:00 2001 From: John Clayton Date: Thu, 3 Dec 2020 08:17:57 -0500 Subject: [PATCH 3/3] Merging in some changes from master and committing changes to scalar handling --- mogenerator.m | 17 +++++++++++++++++ mogenerator.xcodeproj/project.pbxproj | 1 + momcom/NSEntityDescription+momcom.m | 3 --- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/mogenerator.m b/mogenerator.m index 752844e7..7633004d 100644 --- a/mogenerator.m +++ b/mogenerator.m @@ -211,6 +211,15 @@ - (NSString*)customSuperentity { return forcedBaseClass; } } + +- (NSString*)sanitizedCustomSuperentity { + NSString *customSuperentity = [self customSuperentity]; + if ([customSuperentity hasPrefix:@"."]) { + return [customSuperentity stringByReplacingOccurrencesOfString:@"." withString:@""]; + } + return customSuperentity; +} + - (NSString*)forcedCustomBaseClass { NSString* userInfoCustomBaseClass = [[self userInfo] objectForKey:kCustomBaseClass]; return userInfoCustomBaseClass ? userInfoCustomBaseClass : gCustomBaseClassForced; @@ -447,6 +456,7 @@ - (BOOL)hasScalarAttributeType { case NSInteger16AttributeType: case NSInteger32AttributeType: case NSInteger64AttributeType: + case NSDecimalAttributeType: case NSDoubleAttributeType: case NSFloatAttributeType: case NSBooleanAttributeType: @@ -490,6 +500,9 @@ - (NSString*)scalarAttributeType { case NSInteger64AttributeType: return gSwift ? isUnsigned ? @"UInt64" : @"Int64" : isUnsigned ? @"uint64_t" : @"int64_t"; break; + case NSDecimalAttributeType: + return gSwift ? @"Decimal" : @"NSDecimalNumber"; + break; case NSDoubleAttributeType: return gSwift ? @"Double" : @"double"; break; @@ -1220,6 +1233,10 @@ - (int)application:(DDCliApplication*)app runWithArguments:(NSArray*)arguments { generatedHumanM = [generatedHumanM stringByReplacingOccurrencesOfRegex:searchPattern withString:replacementString]; NSString *entityClassName = [entity managedObjectClassName]; + if ([entityClassName.firstLetter compare:@"."] == NSOrderedSame) { + // If default module specified, "MyClass" -> ".MyClass" -> "_MyClass"/"__MyClass" + entityClassName = [entityClassName substringFromIndex:1]; + } entityClassName = [entityClassName stringByReplacingOccurrencesOfString:@"." withString:@"_"]; BOOL machineDirtied = NO; diff --git a/mogenerator.xcodeproj/project.pbxproj b/mogenerator.xcodeproj/project.pbxproj index b799181e..da31cc17 100644 --- a/mogenerator.xcodeproj/project.pbxproj +++ b/mogenerator.xcodeproj/project.pbxproj @@ -217,6 +217,7 @@ ); name = mogenerator; sourceTree = ""; + usesTabs = 0; }; 08FB7795FE84155DC02AAC07 /* Source */ = { isa = PBXGroup; diff --git a/momcom/NSEntityDescription+momcom.m b/momcom/NSEntityDescription+momcom.m index 5fbdbfec..662883e7 100644 --- a/momcom/NSEntityDescription+momcom.m +++ b/momcom/NSEntityDescription+momcom.m @@ -28,9 +28,6 @@ + (NSEntityDescription *)baseEntityForXML:(NSXMLElement *)xmlNode if ([attributeName isEqualToString:@"name"]) { [entityDescription setName:attributeString]; } else if ([attributeName isEqualToString:@"representedClassName"]) { - if ([attributeString hasPrefix:@"."]) { - attributeString = [attributeString substringFromIndex:1]; - } [entityDescription setManagedObjectClassName:attributeString]; } else if ([attributeName isEqualToString:@"elementID"]) { [entityDescription setRenamingIdentifier:attributeString];