From 536bc0f6692332fd1cd8cc407153a5c8164cd285 Mon Sep 17 00:00:00 2001 From: Alexander Zats Date: Fri, 13 Apr 2012 20:23:34 +0300 Subject: [PATCH] Added support for xcdatamodeld bundle (current version will be chosen automatically) --- mogenerator.m | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mogenerator.m b/mogenerator.m index f17b870a..53a0c6f8 100644 --- a/mogenerator.m +++ b/mogenerator.m @@ -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]){