Ben Hello.

thanks for the reply, 
There is something wrong, yes, .
On Mar 30, 2010, at 12:01 AM, Ben Trumbull wrote:

>> So was digging more into the problem, and realize that  the Items are being 
>> saved the ItemXInvoice are being saved and related to the invoice, but I 
>> can't acces the invoice detail (ItemXInvoice) immediately I get a console 
>> error:
> 
> The array controller doesn't appreciate what you're doing to it.  Is there a 
> reason you haven't just configured it in Entity mode with an Entity name and 
> a Managed Object Context binding ?  Then the array controller will just 
> listen to the NSManagedObjectContext notifications and do most of this for 
> you.
> 
The arrray controller its configured with a Entity ItemXInvoice, and the 
Application delegate's MOC, 

>> Cannot remove an observer <NSTableBinder 0x116087000> for the key path 
>> "toItem.descr" from <ItemXInvoice 0x116024800>, most likely because the 
>> value for the key "toItem" has changed without an appropriate KVO 
>> notification being sent. Check the KVO-compliance of the ItemXInvoice class.
> 
> Somewhere you've changed the toItem property without going through the setter 
> method properly.
> 
>> I then checked the class and in the setItem Im doing:
>> 
>> -(void)setToItem:(Item *)value{
>>      [self willChangeValueForKey:@"toItem"];
>>      [value retain];
>>      [self setPrimitiveValue:value forKey:@"toItem"];
>>      [self didChangeValueForKey:@"toItem"];
>> }
As today I deleted these method. I dunno why I put it, I was trying to show my 
colleague something,  but then I wrote it here just in case.

> 
> Where'd you get this ?  It's not from any of the Xcode templates, and it's 
> wrong (leaks).  There is no need to retain value, and since this setter 
> doesn't do anything interesting, you should just delete it and use the 
> @dynamic property from the Xcode Design menu -> Data  Modeling -> Copy 
> Objective-C 2.0 Method Declarations to Clipboard
> 
>> -(IBAction)addItemXInvoice:(id)sender{
>> 
>>      Item  * newItem = [NSEntityDescription 
>> insertNewObjectForEntityForName:@"Item" inManagedObjectContext:[self 
>> managedObjectContext]];
>>      ItemXInvoice * newItemXInvoice = [NSEntityDescription 
>> insertNewObjectForEntityForName:@"ItemXInvoice" inManagedObjectContext: 
>> [self managedObjectContext]];
>>      [newItemXInvoice willChangeValueForKey:@"toItem"];
>>      [newItemXInvoice setValue:newItem forKey:@"toItem"];
>>      [newItemXInvoice didChangeValueForKey:@"toItem"];
>>      [_itemsArrayController addObject:newItemXInvoice];
>>      if(_newInvoice == nil){
>>              _newInvoice = [NSEntityDescription 
>> insertNewObjectForEntityForName:@"Invoice" inManagedObjectContext:[self 
>> managedObjectContext]];
>>      }               
>>      [_newInvoice addToItemsXInvoiceObject:newItemXInvoice];
>>      [_tempItemsArray addObject:newItem]; //I need to keep track of the 
>> newly created itmes by this method so I can safelty remove them.
>>      //Set the creationItemPrice for each ItemXInvoice
>>      
>> 
>> }
> 
> uhm.   lots of not healthy things here.  You shouldn't be calling 
> -willChange/-didChange explicitly here.  That's the purpose of the setter 
> methods (or KVC).  Not sure why a bunch of this code isn't in 
> -awakeFromInsert.  Or why you have _tempItemsArray at all.
> 

the _tempItemArray, I have it because Im able to add new item with the + 
button, which call the above method, and from a pop up button which has the 
previously created items,  so when removing I will delete only the items that 
exist in that array, which means were created using the + button and not the 
pop up button, so the MO that are boud to the pop up button will not disappear 
also,.....  that was my thought ... 
> As others have noted, Cocoa Bindings isn't your Model layer and trying to use 
> it that way is both tedious and error prone.  It's the Controller layer that 
> intermediates between your Model objects and the UI.  You really want to 
> focus these kinds object graph (data management) operations on the Core Data 
> objects, and leverage those APIs along with KVO and NSNotification.
> 
> - Ben
> 
> 
> 

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to