Skip to content

Commit

Permalink
Merge pull request #102 from alexanderzats/master
Browse files Browse the repository at this point in the history
.xcdatamodeld bundle detection
  • Loading branch information
rentzsch committed Apr 13, 2012
2 parents b08eede + 536bc0f commit 00e21f6
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions mogenerator.m
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,21 @@ - (void)setModel:(NSString*)path;
{
assert(!model); // Currently we only can load one model.

// We will try to detect a bundle, not sure about compatabilty with the older Xcode versions
BOOL isDirectory = NO;
// it's a directory, let's try to find a ".xccurrentversion" file so we can locate current version of the model
if ([[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDirectory] && isDirectory) {
// in 4.x version of Xcode there is a .xccurrentversion plist with _XCCurrentVersionName key pointing to the current model
NSString *xccurrentversionPath = [path stringByAppendingPathComponent:@".xccurrentversion"];
if ([[NSFileManager defaultManager] fileExistsAtPath:xccurrentversionPath]) {
NSDictionary *xccurrentversionPlist = [NSDictionary dictionaryWithContentsOfFile:xccurrentversionPath];
NSString *currentModelName = [xccurrentversionPlist valueForKey:@"_XCCurrentVersionName"];
if (currentModelName) {
path = [path stringByAppendingPathComponent:currentModelName];
}
}
}

origModelBasePath = [path stringByDeletingLastPathComponent];

if( ![[NSFileManager defaultManager] fileExistsAtPath:path]){
Expand Down

0 comments on commit 00e21f6

Please sign in to comment.