Skip to content

Commit

Permalink
Support newly-created models when --model=*.xcdatamodeld
Browse files Browse the repository at this point in the history
When models are freshly created, they only have one version and no 
.xccurrentversion file.  In this case, and only in this case, assume the 
only present model is the desired model.
  • Loading branch information
Sergey Grankin committed Nov 20, 2012
1 parent 82b097d commit a3e914b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions mogenerator.m
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,16 @@ - (void)setModel:(NSString*)momOrXCDataModelFilePath {
momOrXCDataModelFilePath = [momOrXCDataModelFilePath stringByAppendingPathComponent:currentModelName];
}
}
else {
// Freshly created models with only one version do NOT have a .xccurrentversion file, but only have one model
// in them. Use that model.
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self endswith %@", @".xcdatamodel"];
NSArray *contents = [[fm contentsOfDirectoryAtPath:momOrXCDataModelFilePath error:nil]
filteredArrayUsingPredicate:predicate];
if (contents.count == 1) {
momOrXCDataModelFilePath = [momOrXCDataModelFilePath stringByAppendingPathComponent:[contents lastObject]];
}
}
}

NSString *momFilePath = nil;
Expand Down

0 comments on commit a3e914b

Please sign in to comment.