• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Detecting reading a key in KVC
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Detecting reading a key in KVC


  • Subject: Re: Detecting reading a key in KVC
  • From: "email@hidden" <email@hidden>
  • Date: Wed, 10 Nov 2010 14:10:03 +0000


On 10 Nov 2010, at 14:05, Quincey Morris wrote:

> On Nov 10, 2010, at 05:58, email@hidden 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 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 the mean time a "wrong" value is returned. How can I detect a read of a property?
>>>
>>> Kind regards,
>>>
>>> Remco Poelstra
>>>
>>>
>>
>> Try overriding your objects -valueForKey: and -valueForKeyPath:
>> NSKeyValueCoding is implemented as a category on NSObject so will be available on your object.
>
> Unless I'm missing something, that isn't necessary. The OP just needs to write a getter for the property.
>
> For a property "abc", he'd do something like this:
>
> // @synthesize abc;  (don't need this any more)
>
> - (NSString*) abc {
> 	if (... we already fetched the value from the network ...)
> 		return ... the correct value ...
> 	else {
> 		... start the network access ...
> 		return ... a temporary value ...
> 	}
> }
>
> That works even if the value is accessed via [... valueForKey: @"abc"], because the default implementation in NSObject will call the getter 'abc' if it exists.


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.

Regards

Jonathan Mitchell

Developer
Mugginsoft LLP
http://www.mugginsoft.com

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Detecting reading a key in KVC
      • From: Quincey Morris <email@hidden>
References: 
 >Detecting reading a key in KVC (From: Remco Poelstra <email@hidden>)
 >Re: Detecting reading a key in KVC (From: "email@hidden" <email@hidden>)
 >Re: Detecting reading a key in KVC (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: image arithmetic
  • Next by Date: Re: Detecting reading a key in KVC
  • Previous by thread: Re: Detecting reading a key in KVC
  • Next by thread: Re: Detecting reading a key in KVC
  • Index(es):
    • Date
    • Thread