Skip to content

Commit

Permalink
Better way of handling unsaved.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrandonw committed Jan 19, 2015
1 parent c49db59 commit d0ac770
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions OPExtensionKit/Source/CoreData/NSManagedObject+Opetopic.m
Expand Up @@ -12,7 +12,7 @@
@implementation NSManagedObject (Opetopic)

-(BOOL) isUnsaved {
return [[self committedValuesForKeys:nil] count] == 0;
return self.objectID.isTemporaryID;
}

-(void) fault {
Expand All @@ -22,26 +22,26 @@ -(void) fault {
}

-(void) addToContext:(NSManagedObjectContext*)context {
if (! self.managedObjectContext)
{
[context insertObject:self];
// first add all relationships to the context
NSDictionary *relationships = [[self entity] relationshipsByName];
[relationships enumerateKeysAndObjectsUsingBlock:^(id relationshipKey, NSRelationshipDescription *relationshipDescription, BOOL *stop) {
id relationship = [self valueForKey:relationshipKey];
if ([relationship conformsToProtocol:@protocol(NSFastEnumeration)])
{
for (NSManagedObject *object in relationship)
[object addToContext:context];
}
else
{
[relationship addToContext:context];
}
}];
}
if (! self.managedObjectContext)
{
[context insertObject:self];

// first add all relationships to the context
NSDictionary *relationships = [[self entity] relationshipsByName];
[relationships enumerateKeysAndObjectsUsingBlock:^(id relationshipKey, NSRelationshipDescription *relationshipDescription, BOOL *stop) {

id relationship = [self valueForKey:relationshipKey];
if ([relationship conformsToProtocol:@protocol(NSFastEnumeration)])
{
for (NSManagedObject *object in relationship)
[object addToContext:context];
}
else
{
[relationship addToContext:context];
}
}];
}
}

@end

0 comments on commit d0ac770

Please sign in to comment.