Re: Detecting reading a key in KVC

2010-11-12 Thread Quincey Morris
On Nov 12, 2010, at 12:05, Remco Poelstra wrote: > If I understand it correctly, for all properties, each and everytime, > valueForUndefinedKey is called? Correct. > So I do also need to override setValue:forUndefinedKey in case 2? To make > sure that the properties end up in the dictionary?

Re: Detecting reading a key in KVC

2010-11-12 Thread Remco Poelstra
Op 12 nov 2010, om 20:44 heeft Quincey Morris het volgende geschreven: In case 2, which seems like the superior solution, the private dictionary isn't being accessed via KVC at all, so the only KVC behavior you're concerned with is that of the wrapper. Ah, that explains. If I understand i

Re: Detecting reading a key in KVC

2010-11-12 Thread Quincey Morris
On Nov 12, 2010, at 11:13, Remco Poelstra wrote: > Otherwise the valueForKey is called on my wrapper, instead of the dictionary > that contains the real keys. I don't see how else the KVC logic should find > out about that instance variable. The dictionary is a private implementation detail of

Re: Detecting reading a key in KVC

2010-11-12 Thread Remco Poelstra
Op 12 nov 2010, om 19:16 heeft Quincey Morris het volgende geschreven: As as been said several times in this thread, you *shouldn't* override 'valueForKey:', but instead override 'valueForUndefinedKey:' like this: Is this kind of override ok?: valueForKey: { [properties valueForKey:

Re: Detecting reading a key in KVC

2010-11-12 Thread Quincey Morris
On Nov 12, 2010, at 10:16, Quincey Morris wrote: > - (id) valueForUndefinedKey: (NSString*) key { > id retVal=[properties objectForKey:key]; // note: NOT 'valueForKey:' > if (!retVal) { > //fetch value from network > //We do not wait for the value > }

Re: Detecting reading a key in KVC

2010-11-12 Thread Quincey Morris
On Nov 12, 2010, at 01:45, Remco Poelstra wrote: > @interface PropertiesController: NSObject { > NSMutableDictionary *properties; > } > > -valueForKey: > -setValue:forKey: > @end > @implementation PropertiesController > valueForKey { > id retVal=[properties valueForKey:key]; >

Re: Detecting reading a key in KVC

2010-11-12 Thread Remco Poelstra
Op 12 nov 2010, om 13:37 heeft Graham Cox het volgende geschreven: > > On 12/11/2010, at 11:24 PM, Remco Poelstra wrote: > >> But if I do not override setValue:forKey: How does the KVC logic now that it >> should not try to call setValue:forKey: on my wrapper object, but on the >> enclosed di

Re: Detecting reading a key in KVC

2010-11-12 Thread Graham Cox
On 12/11/2010, at 11:24 PM, Remco Poelstra wrote: > But if I do not override setValue:forKey: How does the KVC logic now that it > should not try to call setValue:forKey: on my wrapper object, but on the > enclosed dictionary instead? Do I not need to override setValue:forKey: and > call [myDi

Re: Detecting reading a key in KVC

2010-11-12 Thread Remco Poelstra
Op 12-11-2010 12:13, Graham Cox schreef: nil from NSDictionary means no value associated with the key (dictionaries cannot store 'nil' as a value) so this is your cue to go fetch. The problem is that the object on which -valueForUndefinedKey: is invoked is the dictionary, not your wrapper, and si

Re: Detecting reading a key in KVC

2010-11-12 Thread Graham Cox
On 12/11/2010, at 8:45 PM, Remco Poelstra wrote: > If I ommit the valueForKey method, how does the KVC logic now, that it should > check the properties variable? > Further more, NSDictionary seems to always return a value, so all keys are > "defined", they just return nil sometimes. How can val

Re: Detecting reading a key in KVC

2010-11-12 Thread Remco Poelstra
Op 12-11-2010 2:26, Ken Thomases schreef: On Nov 11, 2010, at 4:57 PM, Graham Cox wrote: On 12/11/2010, at 3:30 AM, Ken Thomases wrote: You should not override -setValue:forKey: or -valueForKey: if you can avoid it. Instead, implement the methods -setValue:forUndefinedKey: and -valueForUnde

Re: Detecting reading a key in KVC

2010-11-11 Thread Ken Thomases
On Nov 11, 2010, at 4:57 PM, Graham Cox wrote: > On 12/11/2010, at 3:30 AM, Ken Thomases wrote: > >> You should not override -setValue:forKey: or -valueForKey: if you can avoid >> it. Instead, implement the methods -setValue:forUndefinedKey: and >> -valueForUndefinedKey:. They are precisely f

Re: Detecting reading a key in KVC

2010-11-11 Thread Lee Ann Rucker
On Nov 11, 2010, at 2:57 PM, Graham Cox wrote: > > On 12/11/2010, at 3:30 AM, Ken Thomases wrote: > >> You should not override -setValue:forKey: or -valueForKey: if you can avoid >> it. Instead, implement the methods -setValue:forUndefinedKey: and >> -valueForUndefinedKey:. They are precise

Re: Detecting reading a key in KVC

2010-11-11 Thread Kyle Sluder
On Thu, Nov 11, 2010 at 2:57 PM, Graham Cox wrote: > Understood, but the OP's problem as I understand it is that it's not that the > key is undefined, but the value associated with it is uninitialized. So > rather than return nil, or zero, he wants to trigger a remote fetch of the > value. KVC

Re: Detecting reading a key in KVC

2010-11-11 Thread Graham Cox
On 12/11/2010, at 3:30 AM, Ken Thomases wrote: > You should not override -setValue:forKey: or -valueForKey: if you can avoid > it. Instead, implement the methods -setValue:forUndefinedKey: and > -valueForUndefinedKey:. They are precisely for implementing "dynamic" > properties in this manner

Re: Detecting reading a key in KVC

2010-11-11 Thread Ken Thomases
On Nov 11, 2010, at 7:11 AM, Graham Cox wrote: > Just write a wrapper for -setObject:forKey: and -valueForKey: The first just > calls the same method on its (mutable) dictionary, the second can first check > for whether the value is actually present and if not kick off some task to > fetch it,

Re: Detecting reading a key in KVC

2010-11-11 Thread Remco Poelstra
Op 11-11-2010 14:11, Graham Cox schreef: On 12/11/2010, at 12:01 AM, Remco Poelstra wrote: Seems so :) I just tried that and observing the change of properties is now non-functional, as the request for observing is not forwarded to the NSDictionary behind my own object. Seems I've to overrid

Re: Detecting reading a key in KVC

2010-11-11 Thread Graham Cox
On 12/11/2010, at 12:01 AM, Remco Poelstra wrote: > Seems so :) I just tried that and observing the change of properties is now > non-functional, as the request for observing is not forwarded to the > NSDictionary behind my own object. Seems I've to override a whole lot of > methods to forward

Re: Detecting reading a key in KVC

2010-11-11 Thread Remco Poelstra
Op 11-11-2010 13:48, Graham Cox schreef: On 11/11/2010, at 11:41 PM, Remco Poelstra wrote: Leaves me wondering whether I should hardcode all properties (82 items) on my own object or try to make a more intelligent subclass of NSMutableDictionary. Or maybe a composite object? If the requir

Re: Detecting reading a key in KVC

2010-11-11 Thread jonat...@mugginsoft.com
On 11 Nov 2010, at 12:41, Remco Poelstra wrote: > Op 10-11-2010 15:31, Quincey Morris schreef: >> On Nov 10, 2010, at 06:10, jonat...@mugginsoft.com wrote: >> >>> I was just thinking that the overrides would provide a convenient point to >>> process all requests for undefined properties. >>> D

Re: Detecting reading a key in KVC

2010-11-11 Thread Graham Cox
On 11/11/2010, at 11:41 PM, Remco Poelstra wrote: > Leaves me wondering whether I should hardcode all properties (82 items) on my > own object or try to make a more intelligent subclass of NSMutableDictionary. > Or maybe a composite object? If the requirement is simply to distinguish between

Re: Detecting reading a key in KVC

2010-11-11 Thread Remco Poelstra
Op 10-11-2010 15:31, Quincey Morris schreef: On Nov 10, 2010, at 06:10, jonat...@mugginsoft.com wrote: I was just thinking that the overrides would provide a convenient point to process all requests for undefined properties. Depends on the design and requirements of the model I suppose. I do

Re: Detecting reading a key in KVC

2010-11-10 Thread Quincey Morris
On Nov 10, 2010, at 06:10, jonat...@mugginsoft.com wrote: > I was just thinking that the overrides would provide a convenient point to > process all requests for undefined properties. > Depends on the design and requirements of the model I suppose. I don't think that's happening here -- the prop

Re: Detecting reading a key in KVC

2010-11-10 Thread jonat...@mugginsoft.com
On 10 Nov 2010, at 14:05, Quincey Morris wrote: > On Nov 10, 2010, at 05:58, jonat...@mugginsoft.com wrote: > >> On 10 Nov 2010, at 12:47, Remco Poelstra wrote: >> >>> Hi, >>> >>> I've an object which properties I access via key-value coding. These >>> properties are sometimes "uninitialized

Re: Detecting reading a key in KVC

2010-11-10 Thread Quincey Morris
On Nov 10, 2010, at 05:58, jonat...@mugginsoft.com wrote: > On 10 Nov 2010, at 12:47, Remco Poelstra wrote: > >> Hi, >> >> I've an object which properties I access via key-value coding. These >> properties are sometimes "uninitialized" (that means, the real value needs >> to be read from the W

Re: Detecting reading a key in KVC

2010-11-10 Thread jonat...@mugginsoft.com
On 10 Nov 2010, at 12:47, Remco Poelstra wrote: > Hi, > > I've an object which properties I access via key-value coding. These > properties are sometimes "uninitialized" (that means, the real value needs to > be read from the Wifi network). I would like to detect a read of such > property and

Detecting reading a key in KVC

2010-11-10 Thread Remco Poelstra
Hi, I've an object which properties I access via key-value coding. These properties are sometimes "uninitialized" (that means, the real value needs to be read from the Wifi network). I would like to detect a read of such property and then fetch it from the network. It's not a problem that in th