rentzsch avatar rentzsch committed 4ad6eb6

[FIX] Add missing CoreData+JRExtensions.[hm] files.

Comments (0)

Files changed (3)

CoreData+JRExtensions.h

+/*******************************************************************************
+	CoreData+JRExtensions.h
+		Copyright (c) 2006-2007 Jonathan 'Wolf' Rentzsch: <http://rentzsch.com>
+		Some rights reserved: <http://opensource.org/licenses/mit-license.php>
+
+	***************************************************************************/
+
+#import <Cocoa/Cocoa.h>
+
+@interface NSManagedObject (JRExtensions)
++ (id)newInManagedObjectContext:(NSManagedObjectContext*)moc_;
+- (id)initAndInsertIntoManagedObjectContext:(NSManagedObjectContext*)moc_;
+
++ (id)rootObjectInManagedObjectContext:(NSManagedObjectContext*)moc_;
++ (id)rootObjectInManagedObjectContext:(NSManagedObjectContext*)moc_ error:(NSError**)error_;
+
++ (NSArray*)fetchAllInManagedObjectContext:(NSManagedObjectContext*)moc_;
++ (NSArray*)fetchAllInManagedObjectContext:(NSManagedObjectContext*)moc_ error:(NSError**)error_;
+
++ (NSString*)entityNameByHeuristic; // MyCoolObjectMO => @"MyCoolObject".
++ (NSEntityDescription*)entityDescriptionInManagedObjectContext:(NSManagedObjectContext*)moc_;
++ (NSFetchRequest*)fetchRequestForEntityInManagedObjectContext:(NSManagedObjectContext*)moc_;
+
++ (NSString*)defaultSortKeyWithManagedObjectContext:(NSManagedObjectContext*)moc_;
+
+- (NSString*)objectURLID;
+@end
+
+@interface NSManagedObjectContext (JRExtensions)
+- (NSArray*)executeFetchRequestNamed:(NSString*)fetchRequestName_;
+- (NSArray*)executeFetchRequestNamed:(NSString*)fetchRequestName_ error:(NSError**)error_;
+- (NSArray*)executeFetchRequestNamed:(NSString*)fetchRequestName_ substitutionVariables:(NSDictionary*)variables_;
+- (NSArray*)executeFetchRequestNamed:(NSString*)fetchRequestName_ substitutionVariables:(NSDictionary*)variables_ error:(NSError**)error_;
+- (id)executeSingleResultFetchRequestNamed:(NSString*)fetchRequestName_ substitutionVariables:(NSDictionary*)variables_ error:(NSError**)error_;
+
+- (id)objectWithURLID:(NSString*)url_;
+@end
+

CoreData+JRExtensions.m

+/*******************************************************************************
+	CoreData+JRExtensions.m
+		Copyright (c) 2006-2007 Jonathan 'Wolf' Rentzsch: <http://rentzsch.com>
+		Some rights reserved: <http://opensource.org/licenses/mit-license.php>
+
+	***************************************************************************/
+
+#import "CoreData+JRExtensions.h"
+
+@implementation NSManagedObject (JRExtensions)
+
++ (id)newInManagedObjectContext:(NSManagedObjectContext*)moc_ {
+	return [[self alloc] initAndInsertIntoManagedObjectContext:moc_];
+}
+
+- (id)initAndInsertIntoManagedObjectContext:(NSManagedObjectContext*)moc_ {
+	return [NSEntityDescription insertNewObjectForEntityForName:[[[self class] entityDescriptionInManagedObjectContext:moc_] name]
+										 inManagedObjectContext:moc_];
+}
+
++ (id)rootObjectInManagedObjectContext:(NSManagedObjectContext*)moc_ error:(NSError**)error_ {
+	NSError *error = nil;
+	NSArray *objects = [moc_ executeFetchRequest:[self fetchRequestForEntityInManagedObjectContext:moc_] error:&error];
+	NSAssert( objects, @"-[NSManagedObjectContext executeFetchRequest] returned nil" );
+	
+	id result = nil;
+	
+	switch( [objects count] ) {
+		case 0:
+			[[moc_ undoManager] disableUndoRegistration];
+			result = [self newInManagedObjectContext:moc_];
+			[moc_ processPendingChanges];
+			[[moc_ undoManager] enableUndoRegistration];
+			break;
+		case 1:
+			result = [objects objectAtIndex:0];
+			break;
+		default:
+			NSAssert2( NO, @"0 or 1 %@ objects expected, %d found", [self className], [objects count] );
+	}
+	
+	if (error_) {
+		*error_ = error;
+	}
+	
+	return result;
+}
+
++ (id)rootObjectInManagedObjectContext:(NSManagedObjectContext*)moc_ {
+	NSError *error = nil;
+	id result = [self rootObjectInManagedObjectContext:moc_ error:&error];
+	if (error) {
+		[NSApp presentError:error];
+	}
+	return result;
+}
+
++ (NSString*)entityNameByHeuristic {
+	NSString *result = [self className];
+	if( [result hasSuffix:@"MO"] ) {
+		result = [result substringToIndex:([result length]-2)];
+	}
+	return result;
+}
+
++ (NSEntityDescription*)entityDescriptionInManagedObjectContext:(NSManagedObjectContext*)moc_ {
+	NSEntityDescription *result = [NSEntityDescription entityForName:[self entityNameByHeuristic] inManagedObjectContext:moc_];
+	if( nil == result ) {
+		// Heuristic failed. Do it the hard way.
+		NSString *className = [self className];
+		NSManagedObjectModel *managedObjectModel = [[moc_ persistentStoreCoordinator] managedObjectModel];
+		NSArray *entities = [managedObjectModel entities];
+		unsigned entityIndex = 0, entityCount = [entities count];
+		for( ; nil == result && entityIndex < entityCount; ++entityIndex ) {
+			if( [[[entities objectAtIndex:entityIndex] managedObjectClassName] isEqualToString:className] ) {
+				result = [entities objectAtIndex:entityIndex];
+			}
+		}
+		NSAssert1( result, @"no entity found with a managedObjectClassName of %@", className );
+	}
+	return result;
+}
+
++ (NSFetchRequest*)fetchRequestForEntityInManagedObjectContext:(NSManagedObjectContext*)moc_ {
+	NSFetchRequest *result = [[[NSFetchRequest alloc] init] autorelease];
+	[result setEntity:[self entityDescriptionInManagedObjectContext:moc_]];
+	NSString *defaultSortKey = [self defaultSortKeyWithManagedObjectContext:moc_];
+	if (defaultSortKey) {
+		[result setSortDescriptors:[NSArray arrayWithObject:[[[NSSortDescriptor alloc] initWithKey:defaultSortKey ascending:YES] autorelease]]];
+	}
+	return result;
+}
+
++ (NSArray*)fetchAllInManagedObjectContext:(NSManagedObjectContext*)moc_ {
+	NSError *error = nil;
+	NSArray *result = [self fetchAllInManagedObjectContext:moc_ error:nil];
+	if (error) {
+		[NSApp presentError:error];
+	}
+	return result;
+}
+
++ (NSArray*)fetchAllInManagedObjectContext:(NSManagedObjectContext*)moc_ error:(NSError**)error_ {
+	return [moc_ executeFetchRequest:[self fetchRequestForEntityInManagedObjectContext:moc_]
+							   error:error_];
+}
+
++ (NSString*)defaultSortKeyWithManagedObjectContext:(NSManagedObjectContext*)moc_ {
+	NSString *result = nil;
+	NSEntityDescription *entityDesc = [self entityDescriptionInManagedObjectContext:moc_];
+	if (entityDesc) {
+		result = [[entityDesc userInfo] objectForKey:@"defaultSortKey"];
+		if (!result && [[[entityDesc propertiesByName] allKeys] containsObject:@"position_"]) {
+			result = @"position_";
+		}
+	}
+	return result;
+}
+
+- (NSString*)objectURLID {
+	return [[[self objectID] URIRepresentation] absoluteString];
+}
+
+@end
+
+@implementation NSManagedObjectContext (JRExtensions)
+
+- (NSArray*)executeFetchRequestNamed:(NSString*)fetchRequestName_ {
+	return [self executeFetchRequestNamed:fetchRequestName_ substitutionVariables:nil];
+}
+
+- (NSArray*)executeFetchRequestNamed:(NSString*)fetchRequestName_ error:(NSError**)error_ {
+	return [self executeFetchRequestNamed:fetchRequestName_ substitutionVariables:nil error:error_];
+}
+
+- (NSArray*)executeFetchRequestNamed:(NSString*)fetchRequestName_ substitutionVariables:(NSDictionary*)variables_ {
+	NSError *error = nil;
+	NSArray *result = [self executeFetchRequestNamed:fetchRequestName_ substitutionVariables:variables_ error:&error];
+	if (error) {
+		[NSApp presentError:error];
+	}
+	return result;
+}
+
+#define FetchRequestSortDescriptorsSeemsBroken	1
+
+- (NSArray*)executeFetchRequestNamed:(NSString*)fetchRequestName_ substitutionVariables:(NSDictionary*)variables_ error:(NSError**)error_ {
+	NSManagedObjectModel *model = [[self persistentStoreCoordinator] managedObjectModel];
+	NSFetchRequest *fetchRequest = [model fetchRequestFromTemplateWithName:fetchRequestName_
+													 substitutionVariables:variables_ ? variables_ : [NSDictionary dictionary]];
+	NSAssert1(fetchRequest, @"Can't find fetch request named \"%@\".", fetchRequestName_);
+	
+	NSString *defaultSortKey = nil;
+	Class entityClass = NSClassFromString([[fetchRequest entity] managedObjectClassName]);
+	if ([entityClass respondsToSelector:@selector(defaultSortKeyWithManagedObjectContext:)]) {
+		defaultSortKey = [entityClass defaultSortKeyWithManagedObjectContext:self];
+	}
+	
+#if !FetchRequestSortDescriptorsSeemsBroken
+	if (defaultSortKey) {
+		NSAssert([[fetchRequest sortDescriptors] count] == 0, @"Model-based fetch requests can't have sortDescriptors.");
+		[fetchRequest setSortDescriptors:[NSArray arrayWithObject:[[[NSSortDescriptor alloc] initWithKey:defaultSortKey ascending:YES] autorelease]]];
+	}
+#endif
+	
+	NSArray *result = [self executeFetchRequest:fetchRequest error:error_];
+	
+#if FetchRequestSortDescriptorsSeemsBroken
+	if (defaultSortKey) {
+		result = [result sortedArrayUsingDescriptors:[NSArray arrayWithObject:[[[NSSortDescriptor alloc] initWithKey:defaultSortKey ascending:YES] autorelease]]];
+	}
+#endif
+	return result;
+}
+
+- (id)executeSingleResultFetchRequestNamed:(NSString*)fetchRequestName_ substitutionVariables:(NSDictionary*)variables_ error:(NSError**)error_ {
+	id		result = nil;
+	NSError	*error = nil;
+	
+	NSArray *objects = [self executeFetchRequestNamed:fetchRequestName_ substitutionVariables:variables_ error:&error];
+	NSAssert(objects, nil);
+	
+	if (!error) {
+		switch ([objects count]) {
+			case 0:
+				//	Nothing found matching the fetch request. That's cool, though: we'll just return nil.
+				break;
+			case 1:
+				result = [objects objectAtIndex:0];
+				break;
+			default:
+				NSAssert2(NO, @"%@: 0 or 1 objects expected, %u found", fetchRequestName_, [objects count]);
+		}
+	}
+	
+	if (error_) *error_ = error;
+	return result;
+}
+
+- (id)objectWithURLID:(NSString*)url_ {
+	NSParameterAssert(url_);
+	NSURL *url = [NSURL URLWithString:url_];
+	NSAssert1(url, @"[NSURL URLWithString:@\"%@\"] failed", url_);
+	NSManagedObjectID *objectID = [[self persistentStoreCoordinator] managedObjectIDForURIRepresentation:url];
+	return objectID ? [self objectRegisteredForID:objectID] : nil;
+}
+
+@end

TaskTracker2.xcodeproj/project.pbxproj

 /* Begin PBXBuildFile section */
 		775BDEF1067A8BF0009058FE /* MyDocument.xcdatamodel in Sources */ = {isa = PBXBuildFile; fileRef = 775BDEF0067A8BF0009058FE /* MyDocument.xcdatamodel */; };
 		775DFF38067A968500C5B868 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A7FEA54F5311CA2CBB /* Cocoa.framework */; };
-		7928BE5C0B58A21F0000C258 /* CoreData+PatchRadar4828429.m in Sources */ = {isa = PBXBuildFile; fileRef = 7928BE5B0B58A21F0000C258 /* CoreData+PatchRadar4828429.m */; };
 		793B66BE0822817F00D8D69E /* TaskDocumentMO.m in Sources */ = {isa = PBXBuildFile; fileRef = 793B66BD0822817F00D8D69E /* TaskDocumentMO.m */; };
 		793B66C50822818900D8D69E /* TaskMO.m in Sources */ = {isa = PBXBuildFile; fileRef = 793B66C40822818900D8D69E /* TaskMO.m */; };
 		793B66CC0822819700D8D69E /* TaskPeriodMO.m in Sources */ = {isa = PBXBuildFile; fileRef = 793B66CB0822819700D8D69E /* TaskPeriodMO.m */; };
 		32DBCF750370BD2300C91783 /* TaskTracker2_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TaskTracker2_Prefix.pch; sourceTree = "<group>"; };
 		775BDEF0067A8BF0009058FE /* MyDocument.xcdatamodel */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = wrapper.xcdatamodel; path = MyDocument.xcdatamodel; sourceTree = "<group>"; };
 		7788DA0506752A1600599AAD /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = "<absolute>"; };
-		7928BE5B0B58A21F0000C258 /* CoreData+PatchRadar4828429.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = "CoreData+PatchRadar4828429.m"; path = "../CoreData+PatchRadar4828429/CoreData+PatchRadar4828429.m"; sourceTree = "<group>"; };
 		793B66BC0822817F00D8D69E /* TaskDocumentMO.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TaskDocumentMO.h; sourceTree = "<group>"; };
 		793B66BD0822817F00D8D69E /* TaskDocumentMO.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TaskDocumentMO.m; sourceTree = "<group>"; };
 		793B66C30822818900D8D69E /* TaskMO.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TaskMO.h; sourceTree = "<group>"; };
 		793B66CA0822819700D8D69E /* TaskPeriodMO.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TaskPeriodMO.h; sourceTree = "<group>"; };
 		793B66CB0822819700D8D69E /* TaskPeriodMO.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TaskPeriodMO.m; sourceTree = "<group>"; };
 		79476D810B02EBA90008B0B7 /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = ../../../../../../../../System/Library/Frameworks/Carbon.framework; sourceTree = "<group>"; };
-		79A384340B02579A00386B39 /* CoreData+JRExtensions.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = "CoreData+JRExtensions.h"; path = "../CoreData+JRExtensions/CoreData+JRExtensions.h"; sourceTree = SOURCE_ROOT; };
-		79A384350B02579A00386B39 /* CoreData+JRExtensions.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = "CoreData+JRExtensions.m"; path = "../CoreData+JRExtensions/CoreData+JRExtensions.m"; sourceTree = SOURCE_ROOT; };
+		79A384340B02579A00386B39 /* CoreData+JRExtensions.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = "CoreData+JRExtensions.h"; sourceTree = "<group>"; };
+		79A384350B02579A00386B39 /* CoreData+JRExtensions.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = "CoreData+JRExtensions.m"; sourceTree = "<group>"; };
 		79E11BBA098CA5AB000E8E93 /* Aqua2_Add_Inactive.tif */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = Aqua2_Add_Inactive.tif; sourceTree = "<group>"; };
 		79E11BBB098CA5AB000E8E93 /* Aqua2_Add_Pressed.tif */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = Aqua2_Add_Pressed.tif; sourceTree = "<group>"; };
 		79E11BBC098CA5AB000E8E93 /* Aqua2_Add.tif */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = Aqua2_Add.tif; sourceTree = "<group>"; };
 				79E11D82098D440D000E8E93 /* nsenumerate.h */,
 				79A384340B02579A00386B39 /* CoreData+JRExtensions.h */,
 				79A384350B02579A00386B39 /* CoreData+JRExtensions.m */,
-				7928BE5B0B58A21F0000C258 /* CoreData+PatchRadar4828429.m */,
 			);
 			name = Classes;
 			sourceTree = "<group>";
 			isa = PBXProject;
 			buildConfigurationList = 7993E5B60971D6AB0012DB93 /* Build configuration list for PBXProject "TaskTracker2" */;
 			compatibilityVersion = "Xcode 2.4";
+			developmentRegion = English;
 			hasScannedForEncodings = 1;
+			knownRegions = (
+				English,
+				Japanese,
+				French,
+				German,
+			);
 			mainGroup = 2A37F4AAFDCFA73011CA2CEA /* TaskTracker2 */;
 			projectDirPath = "";
 			projectRoot = "";
 				793B66CC0822819700D8D69E /* TaskPeriodMO.m in Sources */,
 				79E11D5A098D414E000E8E93 /* IntervalFormatter.m in Sources */,
 				79A384360B02579A00386B39 /* CoreData+JRExtensions.m in Sources */,
-				7928BE5C0B58A21F0000C258 /* CoreData+PatchRadar4828429.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
 			isa = XCBuildConfiguration;
 			buildSettings = {
 				GCC_C_LANGUAGE_STANDARD = c99;
+				GCC_VERSION = 4.0;
 				SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk;
 			};
 			name = Development;
 			isa = XCBuildConfiguration;
 			buildSettings = {
 				GCC_C_LANGUAGE_STANDARD = c99;
+				GCC_VERSION = 4.0;
 				SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk;
 			};
 			name = Deployment;
 			isa = XCBuildConfiguration;
 			buildSettings = {
 				GCC_C_LANGUAGE_STANDARD = c99;
+				GCC_VERSION = 4.0;
 				SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk;
 			};
 			name = Default;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.