Permalink
Browse files

[DEV] Update to compile under Xcode 3.2.1 on 10.6.2.

  • Loading branch information...
1 parent bada599 commit a21ee57881a50ba144f5a593ea955b4c8bff37be @rentzsch committed Jan 4, 2010
View
@@ -1,6 +1,6 @@
/*******************************************************************************
JRLog.h
- Copyright (c) 2006-2007 Jonathan 'Wolf' Rentzsch: <http://rentzsch.com>
+ Copyright (c) 2006-2009 Jonathan 'Wolf' Rentzsch: <http://rentzsch.com>
Some rights reserved: <http://opensource.org/licenses/mit-license.php>
***************************************************************************/
View
@@ -1,6 +1,6 @@
/*******************************************************************************
JRLog.m
- Copyright (c) 2006-2007 Jonathan 'Wolf' Rentzsch: <http://rentzsch.com>
+ Copyright (c) 2006-2009 Jonathan 'Wolf' Rentzsch: <http://rentzsch.com>
Some rights reserved: <http://opensource.org/licenses/mit-license.php>
***************************************************************************/
@@ -148,9 +148,11 @@
29B97313FDCFA39411CA2CEA /* Project object */ = {
isa = PBXProject;
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "JRLogDemo" */;
+ compatibilityVersion = "Xcode 2.4";
hasScannedForEncodings = 1;
mainGroup = 29B97314FDCFA39411CA2CEA /* JRLogDemo */;
projectDirPath = "";
+ projectRoot = "";
targets = (
8D1107260486CEB800E47090 /* JRLogDemo */,
);
@@ -237,6 +239,7 @@
C01FCF4F08A954540054247B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ GCC_VERSION = 4.0;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
PREBINDING = NO;
@@ -247,6 +250,7 @@
C01FCF5008A954540054247B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ GCC_VERSION = 4.0;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
PREBINDING = NO;
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ 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
+
View
@@ -0,0 +1,208 @@
+/*******************************************************************************
+ 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
@@ -0,0 +1,37 @@
+#import <Cocoa/Cocoa.h>
+
+@interface NSTableViewPlusCocoaBindingsDeleteKey : NSTableView {}
+@end
+@implementation NSTableViewPlusCocoaBindingsDeleteKey
++ (void)load {
+ [NSTableViewPlusCocoaBindingsDeleteKey poseAsClass:[NSTableView class]];
+}
+
+- (void)keyDown:(NSEvent*)event_ {
+ NSString *eventCharacters = [event_ characters];
+ if ([eventCharacters length]) {
+ switch ([eventCharacters characterAtIndex:0]) {
+ case NSDeleteFunctionKey:
+ case NSDeleteCharFunctionKey:
+ case NSDeleteCharacter: {
+ NSArray *columns = [self tableColumns];
+ unsigned columnIndex = 0, columnCount = [columns count];
+ NSDictionary *valueBindingDict = nil;
+ for (; !valueBindingDict && columnIndex < columnCount; ++columnIndex) {
+ valueBindingDict = [[columns objectAtIndex:columnIndex] infoForBinding:@"value"];
+ }
+ if (valueBindingDict && [[valueBindingDict objectForKey:@"NSObservedObject"] isKindOfClass:[NSArrayController class]]) {
+ // Found a column bound to an array controller.
+ [[valueBindingDict objectForKey:@"NSObservedObject"] remove:self];
+ } else {
+ [super keyDown:event_];
+ }
+ } break;
+ default:
+ [super keyDown:event_];
+ break;
+ }
+ }
+}
+
+@end
Oops, something went wrong.

0 comments on commit a21ee57

Please sign in to comment.