Skip to content

Commit

Permalink
Added support for unsigned integers by setting an integer property's …
Browse files Browse the repository at this point in the history
…minimum value to '0' in the Xcode modeler.
  • Loading branch information
pourhadi committed Jun 26, 2014
1 parent 67f9860 commit e70cab5
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions mogenerator.m
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,17 @@ - (NSArray*)prettyFetchRequests {
@end

@implementation NSAttributeDescription (typing)
- (BOOL)isUnsigned
{
BOOL hasMin = NO;
for (NSPredicate *pred in [self validationPredicates]) {
if ([pred.predicateFormat containsString:@">= 0"]) {
hasMin = YES;
}
}
return hasMin;
}

- (BOOL)hasScalarAttributeType {
switch ([self attributeType]) {
case NSInteger16AttributeType:
Expand All @@ -357,20 +368,23 @@ - (BOOL)hasScalarAttributeType {
}
}
- (NSString*)scalarAttributeType {

BOOL isUnsigned = [self isUnsigned];

NSString *attributeValueScalarType = [[self userInfo] objectForKey:kAttributeValueScalarTypeKey];

if (attributeValueScalarType) {
return attributeValueScalarType;
} else {
switch ([self attributeType]) {
case NSInteger16AttributeType:
return gSwift ? @"Int16" : @"int16_t";
return gSwift ? isUnsigned ? @"UInt16" : @"Int16" : isUnsigned ? @"uint16_t" : @"int16_t";
break;
case NSInteger32AttributeType:
return gSwift ? @"Int32" : @"int32_t";
return gSwift ? isUnsigned ? @"UInt32" : @"Int32" : isUnsigned ? @"uint32_t" : @"int32_t";
break;
case NSInteger64AttributeType:
return gSwift ? @"Int64" : @"int64_t";
return gSwift ? isUnsigned ? @"UInt64" : @"Int64" : isUnsigned ? @"uint64_t" : @"int64_t";
break;
case NSDoubleAttributeType:
return gSwift ? @"Double" : @"double";
Expand All @@ -387,14 +401,26 @@ - (NSString*)scalarAttributeType {
}
}
- (NSString*)scalarAccessorMethodName {

BOOL isUnsigned = [self isUnsigned];

switch ([self attributeType]) {
case NSInteger16AttributeType:
if (isUnsigned) {
return @"unsignedShortValue";
}
return @"shortValue";
break;
case NSInteger32AttributeType:
if (isUnsigned) {
return @"unsignedIntValue";
}
return @"intValue";
break;
case NSInteger64AttributeType:
if (isUnsigned) {
return @"unsignedLongLongValue";
}
return @"longLongValue";
break;
case NSDoubleAttributeType:
Expand All @@ -411,14 +437,26 @@ - (NSString*)scalarAccessorMethodName {
}
}
- (NSString*)scalarFactoryMethodName {

BOOL isUnsigned = [self isUnsigned];

switch ([self attributeType]) {
case NSInteger16AttributeType:
if (isUnsigned) {
return @"numberWithUnsignedShort:";
}
return @"numberWithShort:";
break;
case NSInteger32AttributeType:
if (isUnsigned) {
return @"numberWithUnsignedInt:";
}
return @"numberWithInt:";
break;
case NSInteger64AttributeType:
if (isUnsigned) {
return @"numberWithUnsignedLongLong:";
}
return @"numberWithLongLong:";
break;
case NSDoubleAttributeType:
Expand Down

0 comments on commit e70cab5

Please sign in to comment.