Code Search for Developers
 
 
  

FlitKeyMO.m from redshed at Krugle


Show FlitKeyMO.m syntax highlighted

#import "FlitKeyMO.h"
#import "FlitSlotMO.h"
#import "NSAssert0.h"
#import "NSManagedObject-JRExtensions.h"

@implementation FlitKeyMO

+ (id)keyForKeyName:(NSString*)name_ InManagedObjectContext:(NSManagedObjectContext*)moc_ {
	NSParameterAssert(name_);
	NSParameterAssert(moc_);
	
	//
	NSError *error = nil;
	NSArray *fetchResult = [self fetchWithTemplate:@"keyForKeyName"
							 substitutionVariables:[NSDictionary dictionaryWithObject:name_ forKey:@"keyName"]
							inManagedObjectContext:moc_
											 error:&error];
	if (error)
		return nil;
	NSAssert0(fetchResult);
	NSLog(@"fetchResult keys:%@", fetchResult);
	NSLog(@"all keys:%@", [self fetchAllInManagedObjectContext:moc_]);
	
	//
	FlitKeyMO *result = nil;
	switch ([fetchResult count]) {
		case 0:
			[[moc_ undoManager] disableUndoRegistration];
			result = [self newInManagedObjectContext:moc_];
			[result setName:name_];
			[moc_ processPendingChanges];
			[[moc_ undoManager] enableUndoRegistration];
			break;
		case 1:
			result = [fetchResult objectAtIndex:0];
			break;
		default:
			NSAssert2(NO, @"0 or 1 %@ objects expected, %d found", [self className], [fetchResult count]);
	}
	return result;
}

//--

- (NSString *)name 
{
    NSString * tmpValue;
    
    [self willAccessValueForKey: @"name"];
    tmpValue = [self primitiveValueForKey: @"name"];
    [self didAccessValueForKey: @"name"];
    
    return tmpValue;
}

- (void)setName:(NSString *)value 
{
    [self willChangeValueForKey: @"name"];
    [self setPrimitiveValue: value forKey: @"name"];
    [self didChangeValueForKey: @"name"];
}

- (BOOL)validateName: (id *)valueRef error:(NSError **)outError 
{
    // Insert custom validation logic here.
    return YES;
}


- (void)addSlotsObject:(FlitSlotMO *)value 
{    
    NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1];
    
    [self willChangeValueForKey:@"slots" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];
    
    [[self primitiveValueForKey: @"slots"] addObject: value];
    
    [self didChangeValueForKey:@"slots" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];
    
    [changedObjects release];
}

- (void)removeSlotsObject:(FlitSlotMO *)value 
{
    NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1];
    
    [self willChangeValueForKey:@"slots" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects];
    
    [[self primitiveValueForKey: @"slots"] removeObject: value];
    
    [self didChangeValueForKey:@"slots" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects];
    
    [changedObjects release];
}

@end




See more files for this project here

redshed

Code for Mac+WebObjects.

Project homepage: http://sourceforge.net/projects/redshed
Programming language(s): C,Java,Objective C
License: other

  English.lproj/
    InfoPlist.strings
  Flit.xcdatamodel/
    elements
    layout
  Flit.xcodeproj/
    project.pbxproj
    wolf.mode1
    wolf.pbxuser
  FlitKeyMO.h
  FlitKeyMO.m
  FlitSlotMO.h
  FlitSlotMO.m
  Flit_Prefix.pch
  Info.plist
  NSAssert0.h
  NSManagedObject-JRExtensions.h
  NSManagedObject-JRExtensions.m
  nsenumerate.h