• 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: Quincey Morris <email@hidden>
  • Date: Wed, 10 Nov 2010 06:05:42 -0800

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.

_______________________________________________

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: "email@hidden" <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>)

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