Permalink
Browse files

Support newly-created models when --model=*.xcdatamodeld

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...
1 parent 82b097d commit a3e914b10365e1f433155bdd7d87baf88f5cf4b0 @sgrankin sgrankin committed Nov 20, 2012
Showing with 10 additions and 0 deletions.
  1. +10 −0 mogenerator.m
View
@@ -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;

0 comments on commit a3e914b

Please sign in to comment.