From a3e914b10365e1f433155bdd7d87baf88f5cf4b0 Mon Sep 17 00:00:00 2001 From: Sergey Grankin Date: Mon, 19 Nov 2012 17:03:53 -0800 Subject: [PATCH] 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. --- mogenerator.m | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mogenerator.m b/mogenerator.m index acd25af5..202e8075 100644 --- a/mogenerator.m +++ b/mogenerator.m @@ -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;