Re: noob question regarding proxy object returned by -selection method of NSArrayController
On Jun 28, 2008, at 12:43 PM, Stuart Malin wrote: I have a button in the GUI that should cause various changes to the person selected in the table. In the method that is the target of the button's action, I need to get the selected Person object so I can operate on it. I know I could use the -selection method of the NSController to get a proxy object, and then use -valueForKey: and -setValueForKey to operate on the object via the proxy. However, this puts the logic of the manipulations in my appController. I'd rather the collection of manipulations be in the Person class, (i.e., have instance methods in the Person class that update a person object). If I do this (have the update logic in the Person class), then I can't use the proxy object returned by the -selection method of the NSController (because the proxy object doesn't respond to the methods of the backing class). Have you considered binding the button's target to the array controller's selection, and putting the action methods on the Person directly? (You might need to use a model key path of self to get around the proxy-ness.) Cheers, Ken ___ 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 [EMAIL PROTECTED]
Re: noob question regarding proxy object returned by -selection method of NSArrayController
On Jun 29, 2008, at 12:07 AM, Ken Thomases wrote: On Jun 28, 2008, at 12:43 PM, Stuart Malin wrote: I have a button in the GUI that should cause various changes to the person selected in the table. In the method that is the target of the button's action, I need to get the selected Person object so I can operate on it. I know I could use the -selection method of the NSController to get a proxy object, and then use -valueForKey: and -setValueForKey to operate on the object via the proxy. However, this puts the logic of the manipulations in my appController. I'd rather the collection of manipulations be in the Person class, (i.e., have instance methods in the Person class that update a person object). If I do this (have the update logic in the Person class), then I can't use the proxy object returned by the -selection method of the NSController (because the proxy object doesn't respond to the methods of the backing class). Have you considered binding the button's target to the array controller's selection, and putting the action methods on the Person directly? Yes, I see that can do that. My problem is hypothetical -- just test code to get a working understanding of the dynamics. (You might need to use a model key path of self to get around the proxy-ness.) Yes -- Owen Yamauchi pointed out to me the use of self (though not as a part of a model key path). On Jun 28, 2008, at 11:14 AM, Owen Yamauchi wrote: How about [[controller selection] valueForKey:@self]? NSObject has a -self method which just returns the receiver, and since the proxy object must respond to the KVC query as if it were the underlying object, you get the underlying object back. I found this quite intriguing -- and wondered why the -self method worked when I couldn't invoke the instance method I'd made. So I tried Owen's approach, substituting my instance method (that adjusts several of the object's ivars) for self in invoking -valueForKey on the proxy object -- lo and behold, it worked. I guess this shouldn't really have surprised me -- after all, how can the KVC mechanism know if a method is a canonical accessor (rhetorically asked). So long as no arguments need to be passed to the instance method, one can use -valueForKey on the proxy object to execute an arbitrary instance method (i.e., not a canonical getter accessor). But doing this seems wrong to me -- using the KVC mechanism in a way that it isn't intended. I suspect I'll avoid using it, but am curious if this (using KVC to invoke non-canonical getter) is troublesome or not? ___ 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 [EMAIL PROTECTED]
Re: noob question regarding proxy object returned by -selection method of NSArrayController
On Jun 29, 2008, at 10:47 AM, Stuart Malin wrote: On Jun 28, 2008, at 11:14 AM, Owen Yamauchi wrote: How about [[controller selection] valueForKey:@self]? NSObject has a -self method which just returns the receiver, and since the proxy object must respond to the KVC query as if it were the underlying object, you get the underlying object back. I found this quite intriguing -- and wondered why the -self method worked when I couldn't invoke the instance method I'd made. So I tried Owen's approach, substituting my instance method (that adjusts several of the object's ivars) for self in invoking -valueForKey on the proxy object -- lo and behold, it worked. I guess this shouldn't really have surprised me -- after all, how can the KVC mechanism know if a method is a canonical accessor (rhetorically asked). So long as no arguments need to be passed to the instance method, one can use -valueForKey on the proxy object to execute an arbitrary instance method (i.e., not a canonical getter accessor). You might get in trouble if its return type is void. Who knows what - valueForKey: will do in that case? But doing this seems wrong to me -- using the KVC mechanism in a way that it isn't intended. I suspect I'll avoid using it, but am curious if this (using KVC to invoke non-canonical getter) is troublesome or not? Well, it is certainly troublesome from the point of view of code clarity and comprehension. From the point of view of what will happen, it's fairly well defined, so I don't think you're setting yourself up for the code to blow up. That is, the fact that it's working in your test is not just an unreliable fluke. Still, your gut reaction is one I share. Don't do it. However, note that -self is in fact a perfectly fine getter. I have no qualms about using that particular key via KVC. Cheers, Ken ___ 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 [EMAIL PROTECTED]
noob question regarding proxy object returned by -selection method of NSArrayController
Still pursuing my understanding of bindings: I have a table view whose columns are bound to an NSArrayController, which in turn has its contentObject that is a mutable array of Person objects. Person objects have KVC-conforming properties, which provide the values for the data in the columns of the table. This all works. I have a button in the GUI that should cause various changes to the person selected in the table. In the method that is the target of the button's action, I need to get the selected Person object so I can operate on it. I know I could use the -selection method of the NSController to get a proxy object, and then use -valueForKey: and -setValueForKey to operate on the object via the proxy. However, this puts the logic of the manipulations in my appController. I'd rather the collection of manipulations be in the Person class, (i.e., have instance methods in the Person class that update a person object). If I do this (have the update logic in the Person class), then I can't use the proxy object returned by the -selection method of the NSController (because the proxy object doesn't respond to the methods of the backing class). My question is: What is the best way to get the actual model entry, so such instance methods can be invoked? BTW: I have one solution, which is to send the controller a - selectionIndex message, and use the resulting index to directly access the backing store. But doing this is based on knowing what that backing content object is, which seems like I am using side knowledge in my appController, and so I wonder if there is a way to get the actual model content object directly from the 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 [EMAIL PROTECTED]
Re: noob question regarding proxy object returned by -selection method of NSArrayController
6/28/08 11:43 AM, also sprach [EMAIL PROTECTED]: If I do this (have the update logic in the Person class), then I can't use the proxy object returned by the -selection method of the NSController (because the proxy object doesn't respond to the methods of the backing class). My question is: What is the best way to get the actual model entry, so such instance methods can be invoked? I call [[arrayController selectedObjects] objectAtIndex:0] to get the actual object. BTW: I have one solution, which is to send the controller a - selectionIndex message, and use the resulting index to directly access the backing store. But doing this is based on knowing what that backing content object is, which seems like I am using side knowledge in my appController, and so I wonder if there is a way to get the actual model content object directly from the NSArrayController Probably a bad idea. You can't guarantee the order unless, as you say, your controller knows too much about the view. You could use the index but use it on -arrangedObjects, however. HTH, Keary Suska Esoteritech, Inc. Demystifying technology for your home or business ___ 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 [EMAIL PROTECTED]
[SOLVED] noob question regarding proxy object returned by -selection method of NSArrayController
Sorry for the post how did I miss -selectedObjects Begin forwarded message: From: Stuart Malin [EMAIL PROTECTED] Date: June 28, 2008 10:43:36 AM PDT To: Cocoa Developer List cocoa-dev@lists.apple.com Subject: noob question regarding proxy object returned by -selection method of NSArrayController Still pursuing my understanding of bindings: I have a table view whose columns are bound to an NSArrayController, which in turn has its contentObject that is a mutable array of Person objects. Person objects have KVC-conforming properties, which provide the values for the data in the columns of the table. This all works. I have a button in the GUI that should cause various changes to the person selected in the table. In the method that is the target of the button's action, I need to get the selected Person object so I can operate on it. I know I could use the -selection method of the NSController to get a proxy object, and then use -valueForKey: and -setValueForKey to operate on the object via the proxy. However, this puts the logic of the manipulations in my appController. I'd rather the collection of manipulations be in the Person class, (i.e., have instance methods in the Person class that update a person object). If I do this (have the update logic in the Person class), then I can't use the proxy object returned by the -selection method of the NSController (because the proxy object doesn't respond to the methods of the backing class). My question is: What is the best way to get the actual model entry, so such instance methods can be invoked? BTW: I have one solution, which is to send the controller a - selectionIndex message, and use the resulting index to directly access the backing store. But doing this is based on knowing what that backing content object is, which seems like I am using side knowledge in my appController, and so I wonder if there is a way to get the actual model content object directly from the 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 [EMAIL PROTECTED]
Re: [SOLVED] noob question regarding proxy object returned by -selection method of NSArrayController
How about [[controller selection] valueForKey:@self]? NSObject has a -self method which just returns the receiver, and since the proxy object must respond to the KVC query as if it were the underlying object, you get the underlying object back. Owen ___ 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 [EMAIL PROTECTED]