• 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
Bizarre CoreData Problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bizarre CoreData Problem


  • Subject: Bizarre CoreData Problem
  • From: Arved von Brasch <email@hidden>
  • Date: Sat, 6 May 2006 23:41:41 +1000

Greetings,

I have two CoreData entities in a relationship. The relationship is many to one. I have to initialise some values when an object is added on the many list side.

Sounds simple if you've read the "Model Object Implementation Guide" (http://developer.apple.com/documentation/Cocoa/Conceptual/ ModelObjects/ModelObjects.pdf), right? Well, I decided to implement these two methods in my Managed Object subclass:

- (void)addDownloadsObject: (Download *)download {
NSLog(@"Add");

NSSet *changedDownload = [[NSSet alloc] initWithObjects: &download count: 1];
[self willChangeValueForKey: @"downloads" withSetMutation: NSKeyValueUnionSetMutation usingObjects: changedDownload];
[[self primitiveValueForKey: @"downloads"] addObject: changedDownload];
[self didChangeValueForKey: @"downloads" withSetMutation: NSKeyValueUnionSetMutation usingObjects: changedDownload];
[changedDownload release];
}


- (void)removeDownloadsObject: (Download *)download {
NSLog(@"Remove");

NSSet *changedDownload = [[NSSet alloc] initWithObjects: &download count: 1];
[self willChangeValueForKey: @"downloads" withSetMutation: NSKeyValueMinusSetMutation usingObjects: changedDownload];
[[self primitiveValueForKey: @"downloads"] removeObject: changedDownload];
[self didChangeValueForKey: @"downloads" withSetMutation: NSKeyValueMinusSetMutation usingObjects: changedDownload];
[changedDownload release];
}


This follows from the documentation and is exactly what is generated for you, if you leave the "generate accessor methods" checked when creating the subclass. The NSLogs are there for testing purposes, and I've yet to add my necessary code. I have an NSArrayController handle the adding and removing of objects for me in my interface. The trouble is that I cannot get the add method to ever be called. When testing this, a new object is created and successfully joins the to-many relationship list, but without the add method being called. When I remove this same object, the remove method is called twice. I have no other methods in my subclass other than awakeFromInsert. Strangely, I've found that if I implement - (void)setDownloads: (NSMutableArray *)downloads this method will be called when an object is to be added, and the remove method will be called twice as before. I can work with these two methods being called for me, but that is very messy when there is something obviously wrong.

I have tried implementing - (void)addDownloads: (NSSet *)addDownloads and - (void)removeDownloads: (NSSet *)removeDownloads with exactly the same result, the remove method is called twice, and the add method not at all.

My understand from reading the documentation is that these kinds of methods will only be called by mutableSetValueForKey if a pair exist and are properly named. I'm really at a loss to understand why these methods are behaving in this way. Is this a bug?

Cheers,

Arved von Brasch
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Bizarre CoreData Problem
      • From: mmalcolm crawford <email@hidden>
  • Prev by Date: Re: Bindings, a Tableview and an array (Newbie question)
  • Next by Date: Re: Versioning and CoreData
  • Previous by thread: Re: Transparent Overlay Custom View
  • Next by thread: Re: Bizarre CoreData Problem
  • Index(es):
    • Date
    • Thread