Re: NSTableColumn value binding + keypath over a relationship

2009-09-30 Thread Bryan Matteson


I'm going to take a stab in the dark and predict that you *don't*  
have rearranges content automatically checked for the array  
controller,


I do.


and that checking it will cause the error message to go away.


It does not.


Try unchecking it.
http://stackoverflow.com/questions/1028700/core-data-strange-bindings-error-on-re-opening-a-document-help

- Bryan
___

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


Re: NSTableColumn value binding + keypath over a relationship

2009-09-30 Thread Stamenkovic Florijan

On Sep 30, 2009, at 10:22, Bryan Matteson wrote:



I'm going to take a stab in the dark and predict that you *don't*  
have rearranges content automatically checked for the array  
controller,


I do.


and that checking it will cause the error message to go away.


It does not.


Try unchecking it.


I tried it, did not help.

Besides, I need automatic resorting (automatic at least from the  
user's point of view), and this is the cleanest way of doing it.



http://stackoverflow.com/questions/1028700/core-data-strange-bindings-error-on-re-opening-a-document-help


Similar behavior (not the same), and I am not getting any formatter  
related Console messages that are mentioned on that thread. I could be  
messing things up some other way though. Will try to isolate the issue.


F
___

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


NSTableColumn value binding + keypath over a relationship

2009-09-29 Thread Stamenkovic Florijan

Hi all,

I have been experiencing an error in my app that does not make  
sense... Here is the situation:


A CoreData app. I have a table and one of it's columns' value bound to  
an array controller's arrangedObjects.group.title. The controller  
contains objects of the Note entity. Note relates to a Group (to-one),  
and the Group entity has a title attribute. Straightforward. Next to  
the table I have an outline view containing Groups. I have implemented  
drag and drop so that Notes can be dragged from their table to a  
different group in the outline view. However, when I have the above  
described table column present in the table, I get an error after  
dragging that says:


Cannot remove an observer NSTableBinder 0x177eb0 for the key path  
group.name from FSNote 0x1ad240, most likely because the value for  
the key group has changed without an appropriate KVO notification  
being sent. Check the KVO-compliance of the FSNote class.


I am quite certain that the Note class is KVO compliant for group,  
since I don't do anything to prevent it being, and it's a CoreData  
entity with @dynamic property generation.


So, I am wondering, am I doing something wrong? It seems a reasonable  
thing to do, binding a column's value to the  
arrangedObjects.relationship.attribute key path, but maybe that is  
not allowed?


I have managed to work around this by binding the column to  
arrangedObjects.group, and using a custom value transformer. This  
provides me with exactly the functionality I need, but I am still  
wondering about the mechanics, and if I am doing something wrong.


Thanks in advance,
F
___

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


Re: NSTableColumn value binding + keypath over a relationship

2009-09-29 Thread Quincey Morris

On Sep 29, 2009, at 14:18, Stamenkovic Florijan wrote:

A CoreData app. I have a table and one of it's columns' value bound  
to an array controller's arrangedObjects.group.title. The  
controller contains objects of the Note entity. Note relates to a  
Group (to-one), and the Group entity has a title attribute.  
Straightforward. Next to the table I have an outline view containing  
Groups. I have implemented drag and drop so that Notes can be  
dragged from their table to a different group in the outline view.  
However, when I have the above described table column present in the  
table, I get an error after dragging that says:


Cannot remove an observer NSTableBinder 0x177eb0 for the key path group.name 
 from FSNote 0x1ad240, most likely because the value for the key  
group has changed without an appropriate KVO notification being  
sent. Check the KVO-compliance of the FSNote class.


I am quite certain that the Note class is KVO compliant for group,  
since I don't do anything to prevent it being, and it's a CoreData  
entity with @dynamic property generation.


So, I am wondering, am I doing something wrong? It seems a  
reasonable thing to do, binding a column's value to the  
arrangedObjects.relationship.attribute key path, but maybe that is  
not allowed?


The error message specifies group.name, not group.title. Do you  
maybe have a typo in one of your bindings in IB?


KVO compliance doesn't necessarily come automatically, if you don't  
do anything to prevent it. In the case of a simple property, yes,  
*if* you update the property through the proper setter, the KVO  
notifications will occur automatically, but it's easy to get into a  
situation where the update doesn't happen when or as you think. It  
only gets more complicated when key paths are involved, instead of  
single keys.


Also, keep in mind that a path like arrangedObjects.group.title is a  
fiction. arrangedObjects is an array, and each row of the column is  
bound to a different element of the array. arrangedObjects is the  
key path to the array property, group.title is the key path to each  
element. The binding is what bridges that difference -- there is more  
going on behind the scenes than just KVC.


(Because of convenience behavior in NSArray, a key path like  
someArray.somePropertyOfEachArrayElement will actually return an  
array of property values when accessed via KVC, but that reference is  
not in itself KVO compliant.)



___

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


Re: NSTableColumn value binding + keypath over a relationship

2009-09-29 Thread Stamenkovic Florijan

On Sep 29, 2009, at 17:37, Bryan Matteson wrote:

Cannot remove an observer NSTableBinder 0x177eb0 for the key path  
group.name from FSNote 0x1ad240, most likely because the value  
for the key group has changed without an appropriate KVO  
notification being sent. Check the KVO-compliance of the FSNote  
class.


Means exactly what it says. Somewhere you changed the value of a  
group object without using KVC.


So, I am wondering, am I doing something wrong? It seems a  
reasonable thing to do, binding a column's value to the  
arrangedObjects.relationship.attribute key path, but maybe that  
is not allowed?


It IS allowed, and the best way to go about it.

I have managed to work around this by binding the column to  
arrangedObjects.group, and using a custom value transformer. This  
provides me with exactly the functionality I need, but I am still  
wondering about the mechanics, and if I am doing something wrong.


This is probably not correct.

Check your outlineView's delegate methods where you have implemented  
drag and drop. Somewhere along the way you are changing a value  
without using the mutators. If you can't find it, post the relevant  
code (i.e. the all drag-and-drop related code from the outline view)  
and I'll help you spot it.



Bryan, Quincey,

Thanks for your replies. As for the group.name vs. group.title  
that Quincy mentions, it's a typo in the email, not in the project.


As for messing up / not using KVO properly, I suppose that somehow I  
am not, but I don't see how. I have read most of the CoreData docs and  
have experience with similar technologies (WebObjects), and am fairly  
certain I am not doing anything obviously wrong... Also what is  
interesting is that I can


As for what Bryan mentions, that I am changing an attribute in a non- 
KVO-compliant way, I do not think so. In that sense the message I am  
getting is a bit misleading (also note that it says ...most likely  
because...)...


Bryan, you say that my workaround is probably not correct. Why? I  
understand it is a long and not the-right-way, but the-right-way does  
not seem to work for me at the moment.


As for the code in the outline view data source, here it is, I am not  
changing the value without using the mutators, but perhaps it is  
relevant:


- (BOOL)outlineView:(NSOutlineView*)outlineView
 acceptDrop:(id NSDraggingInfo)info
   item:(id)proposedParentItem
 childIndex:(NSInteger)proposedChildIndex
{
NSPasteboard* pboard = [info draggingPasteboard];
NSArray* pboardTypes = [pboard types];

// Notes being dragged
if([pboardTypes containsObject:FSNoteIDURIsArrayPBType]){

// the group dragged to
		NSManagedObject* group = [((NSTreeNode*)proposedParentItem)  
representedObject];


// the URIs of Notes being dragged
NSArray* noteURIs = [NSKeyedUnarchiver
			 unarchiveObjectWithData:[pboard  
dataForType:FSNoteIDURIsArrayPBType]];


NSUndoManager* um = [[group managedObjectContext] undoManager];

// relate the notes to the group dragged into
// do it as a single undoable op
[um beginUndoGrouping];
for(NSURL* noteURI in noteURIs){
			// app delegate is the where the managed object URI - managed  
object reference logic resides

FSNote* note = (FSNote*)[appDelegate 
objectForURI:noteURI];
note.group = group;
}
[um endUndoGrouping];

return YES;
}

// accepting also other drag types (reordering of Groups contained in  
the outline view), code that does that is here

___

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


Re: NSTableColumn value binding + keypath over a relationship

2009-09-29 Thread Quincey Morris

On Sep 29, 2009, at 15:27, Stamenkovic Florijan wrote:


// the group dragged to
		NSManagedObject* group = [((NSTreeNode*)proposedParentItem)  
representedObject];


// the URIs of Notes being dragged
NSArray* noteURIs = [NSKeyedUnarchiver
			 unarchiveObjectWithData:[pboard  
dataForType:FSNoteIDURIsArrayPBType]];


NSUndoManager* um = [[group managedObjectContext] undoManager];

// relate the notes to the group dragged into
// do it as a single undoable op
[um beginUndoGrouping];
for(NSURL* noteURI in noteURIs){
			// app delegate is the where the managed object URI - managed  
object reference logic resides

FSNote* note = (FSNote*)[appDelegate 
objectForURI:noteURI];
note.group = group;
}
[um endUndoGrouping];


I dunno, this is where my head starts to hurt.

According to your error message, there was an observer of a Note  
(well, FSNote) object for key path group.name. However, your binding  
is via arrangedObjects. Now, although the array controller may be KVO  
compliant for the property arrangedObjects, the arrangedObjects  
array isn't itself KVO compliant for anything, because arrays just  
aren't. So although 'note.group = group;' is generating the correct  
notification, maybe it just isn't flowing through the array  
controller to the binding mechanism.


I'm going to take a stab in the dark and predict that you *don't* have  
rearranges content automatically checked for the array controller,  
and that checking it will cause the error message to go away. (Or,  
equivalently, you could send a rearrangeObjects message to the array  
controller immediately after 'note.group = group;'.)


Alternatively, you could move to a small island in the Pacific and  
forget you ever heard of NSArrayController. ;)



___

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


Re: NSTableColumn value binding + keypath over a relationship

2009-09-29 Thread Stamenkovic Florijan


On Sep 29, 2009, at 19:21, Quincey Morris wrote:


On Sep 29, 2009, at 15:27, Stamenkovic Florijan wrote:


// the group dragged to
		NSManagedObject* group = [((NSTreeNode*)proposedParentItem)  
representedObject];


// the URIs of Notes being dragged
NSArray* noteURIs = [NSKeyedUnarchiver
			 unarchiveObjectWithData:[pboard  
dataForType:FSNoteIDURIsArrayPBType]];


NSUndoManager* um = [[group managedObjectContext] undoManager];

// relate the notes to the group dragged into
// do it as a single undoable op
[um beginUndoGrouping];
for(NSURL* noteURI in noteURIs){
			// app delegate is the where the managed object URI - managed  
object reference logic resides

FSNote* note = (FSNote*)[appDelegate 
objectForURI:noteURI];
note.group = group;
}
[um endUndoGrouping];


I dunno, this is where my head starts to hurt.

According to your error message, there was an observer of a Note  
(well, FSNote) object for key path group.name.


I figured that out. And I am fairly sure it is a binding mediator  
between the column and the array controller, because if I remove that  
column, I don't get the error.


However, your binding is via arrangedObjects. Now, although the  
array controller may be KVO compliant for the property  
arrangedObjects, the arrangedObjects array isn't itself KVO  
compliant for anything, because arrays just aren't. So although  
'note.group = group;' is generating the correct notification, maybe  
it just isn't flowing through the array controller to the binding  
mechanism.


Hm... I am thinking something similar. However, it seems to me that  
every item in the contents of an array controller is observed for  
relevant paths. Which can be witnessed when binding a table column's  
value to an attribute of an item in the controller. For example,  
arrangedObjects.firstName in a Person. So, it seems that an array  
controller provides KVO compliance for it's contents (arrangedObjects)  
as well as for the properties of items in that array. My situation  
seems to imply this too. If I bind to arrangedObjects.group, and use  
a value transformer, I get both the correct behavior and updates in  
the NSTableView resulting when I change a Note's group relationship.  
Where it seems to fail is when stretching that path. Somehow the array  
controller seems to be able to handle itemNoX.relationship, but not  
itemNoX.relationship.attribute.


I'm going to take a stab in the dark and predict that you *don't*  
have rearranges content automatically checked for the array  
controller,


I do.


and that checking it will cause the error message to go away.


It does not.

(Or, equivalently, you could send a rearrangeObjects message to  
the array controller immediately after 'note.group = group;'.)


I am not sure where you are going with this, but I have tried it, and  
it does not change the behavior.


F

if nobody comes up with a you are doing this wrong, do it like this  
by tomorrow I will try to isolate this in a small case. Maybe I am  
causing this somewhere else in my code. I think not, but best to check.

___

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