• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Persistent store removal throwing invalidated NSManagedObject exceptions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Persistent store removal throwing invalidated NSManagedObject exceptions


  • Subject: Re: Persistent store removal throwing invalidated NSManagedObject exceptions
  • From: Drew McCormack <email@hidden>
  • Date: Wed, 01 Apr 2009 16:28:41 +0200


Hi Drew,

When writing a custom to-many accessor in an NSManagedObject subclass, you need to invoke the correct KVO -will/didChange methods

These are:

-[NSManagedObject willChangeValueForKey:withSetMutation:usingObjects:]
-[NSManagedObject didChangeValueForKey:withSetMutation:usingObjects:]

So your method should change to:

-(void)removeCollectionsObject:(KnowledgeCollection *)anObject {
NSSet *removedObjects = [[NSSet alloc] initWithObjects:&anObject count:1];
[self willChangeValueForKey:@"collections" withSetMutation:NSKeyValueMinusSetMutation usingObjects:removedObjects];
[[self primitiveValueForKey:@"collections"] removeObject:anObject];
[self didChangeValueForKey:@"collections" withSetMutation:NSKeyValueMinusSetMutation usingObjects:removedObjects];
[removedObjects release];
}


Hope this helps, there's a full example in the programming guide:

http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/CoreData/Articles/cdAccessorMethods.html#/ /apple_ref/doc/uid/TP40002154-SW6

Jonathan

Thanks Jonathan. You're absolutely right.

However, when I made the appropriate changes, I have the same issue: with my new custom remove... accessor, I get the exception, and without the custom accessor, there is no exception. So something strange is still going on.

Here is the new accessor for good measure:

-(void)removeCollectionsObject:(KnowledgeCollection *)anObject {
NSSet *removedObjects = [[NSSet alloc] initWithObjects:&anObject count:1];
[self willChangeValueForKey:@"collections" withSetMutation:NSKeyValueMinusSetMutation usingObjects:removedObjects];
[[self primitiveValueForKey:@"collections"] removeObject:anObject];
[self didChangeValueForKey:@"collections" withSetMutation:NSKeyValueMinusSetMutation usingObjects:removedObjects];
[removedObjects release];
}


Drew
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Persistent store removal throwing invalidated NSManagedObject exceptions
      • From: Jonathan Dann <email@hidden>
References: 
 >Persistent store removal throwing invalidated NSManagedObject exceptions (From: Drew McCormack <email@hidden>)
 >Re: Persistent store removal throwing invalidated NSManagedObject exceptions (From: Jonathan Dann <email@hidden>)

  • Prev by Date: Re: [BUG] Cursor Flicker
  • Next by Date: Re: NSMutableArray is null?
  • Previous by thread: Re: Persistent store removal throwing invalidated NSManagedObject exceptions
  • Next by thread: Re: Persistent store removal throwing invalidated NSManagedObject exceptions
  • Index(es):
    • Date
    • Thread