Skip to content

Commit

Permalink
Merge pull request #395 from seanm/isUnsigned-fix
Browse files Browse the repository at this point in the history
Improved isUnsigned to check attribute minimum more carefully
  • Loading branch information
rentzsch authored Oct 2, 2024
2 parents 2d7f9b4 + af066ac commit 8d463ac
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions mogenerator.m
Original file line number Diff line number Diff line change
Expand Up @@ -442,13 +442,23 @@ - (NSArray*)prettyFetchRequests {
@implementation NSAttributeDescription (typing)
- (BOOL)isUnsigned
{
BOOL hasMin = NO;
BOOL isUnsigned = NO;
for (NSPredicate *pred in [self validationPredicates]) {
if ([pred.predicateFormat containsString:@">= 0"]) {
hasMin = YES;
NSString* formatString = pred.predicateFormat;
NSRange range = [formatString rangeOfString:@"SELF >="];
if (range.location != NSNotFound) {
NSUInteger startIndex = range.location + range.length;
NSString *minString = [formatString substringFromIndex:startIndex];
NSScanner *scanner = [NSScanner scannerWithString:minString];
NSInteger minValue;
BOOL success = [scanner scanInteger:&minValue];
if (success && (minValue >= 0)) {
isUnsigned = YES;
break;
}
}
}
return hasMin;
return isUnsigned;
}

- (BOOL)hasScalarAttributeType {
Expand Down

0 comments on commit 8d463ac

Please sign in to comment.