Can a model key path binding access a super class property

2010-01-17 Thread Grant Christensen
Hi all,

I have two classes, one defining a few base properties, and another more 
specific class inheriting from it.  Example below:

@interface BBSBaseClass : NSObject {
NSString*aValue;
}

@property (readwrite, copy) NSString*aValue;

@end

@interface BBSMoreSpecific : BBSBaseClass {
NSString*anotherValue;  
}
@property (readwrite, assign) NSString  *anotherValue;

@end

In my window I have a NSTableView that is using an array controller to get 
access to my data.  The array controller is bound to an array of 
BBSMoreSpecific classes.

The problem I am having is that all of my columns bound to the fields in the 
BBSMoreSpecific class show their data, but those bound to those in the base 
class do not.  I am using a simple model key path of just the name of the ivar, 
so aValue and anotherValue.

Can the bindings access the base class or can they only access values in the 
class the array controller is directly connected to?

regards,

---
Grant Christensen




___

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: Can a model key path binding access a super class property

2010-01-17 Thread James Bucanek
Grant Christensen mailto:gran...@bigpond.net.au wrote (Sunday, 
January 17, 2010 6:53 AM +1000):



In my window I have a NSTableView that is using an array controller to get
access to my data.  The array controller is bound to an array of
BBSMoreSpecific classes.

The problem I am having is that all of my columns bound to the fields in the
BBSMoreSpecific class show their data, but those bound to those in the base
class do not.  I am using a simple model key path of just the name of the
ivar, so aValue and anotherValue.

Can the bindings access the base class or can they only access values in the
class the array controller is directly connected to?


Of course you can. This is a basic principle of object oriented 
languages (unless there's scoping, but Objective-C doesn't 
support that). You could verify this by using a key-value path 
to access any of the object's NSObject properties, like -description.


I suspect that something else is wrong. Your simplistic example 
appears to be valid, but it's obviously not the code you're 
using. It time to hit the debugger


Since you've declared these as formal properties, KVO should be 
accessing these properties via their accessor methods. One trick 
is to override the base-class getter method in your subclass 
like this:


@implementation BBSMoreSpecific
...
- (NSString*)aValue
{
NSString* value = [super aValue];
//NSLog(@%s returning '%@',__func__,value);
return value;   // -- set breakpoint here
}

Now you can set a breakpoint or log every access to that 
property. You shouldn't have any problem verifying if the 
correct messages are being sent (or not), by whom, and then work 
backwards from there.


--
James Bucanek

___

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


[SOLVED]: Re: Can a model key path binding access a super class property

2010-01-17 Thread Grant Christensen
Thanks for the nudge in the right direction James... I went back to the 
debugger and found an underlying problem with the two variables in the base 
class that were not coming through.  It as a mere coincidence that it was those 
two in the base class, and I was not setting them correctly in the first place. 
  Always the simple answers :)

regards,

Grant

On 18/01/2010, at 3:04 AM, James Bucanek wrote:

 Grant Christensen mailto:gran...@bigpond.net.au wrote (Sunday, January 17, 
 2010 6:53 AM +1000):
 
 In my window I have a NSTableView that is using an array controller to get
 access to my data.  The array controller is bound to an array of
 BBSMoreSpecific classes.
 
 The problem I am having is that all of my columns bound to the fields in the
 BBSMoreSpecific class show their data, but those bound to those in the base
 class do not.  I am using a simple model key path of just the name of the
 ivar, so aValue and anotherValue.
 
 Can the bindings access the base class or can they only access values in the
 class the array controller is directly connected to?
 
 Of course you can. This is a basic principle of object oriented languages 
 (unless there's scoping, but Objective-C doesn't support that). You could 
 verify this by using a key-value path to access any of the object's NSObject 
 properties, like -description.
 
 I suspect that something else is wrong. Your simplistic example appears to be 
 valid, but it's obviously not the code you're using. It time to hit the 
 debugger
 
 Since you've declared these as formal properties, KVO should be accessing 
 these properties via their accessor methods. One trick is to override the 
 base-class getter method in your subclass like this:
 
 @implementation BBSMoreSpecific
 ...
 - (NSString*)aValue
 {
NSString* value = [super aValue];
//NSLog(@%s returning '%@',__func__,value);
return value;   // -- set breakpoint here
 }
 
 Now you can set a breakpoint or log every access to that property. You 
 shouldn't have any problem verifying if the correct messages are being sent 
 (or not), by whom, and then work backwards from there.
 
 -- 
 James Bucanek
 


---
Grant Christensen




___

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