• 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: Binding question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Binding question


  • Subject: Re: Binding question
  • From: Quincey Morris <email@hidden>
  • Date: Tue, 28 Oct 2008 12:58:20 -0700

On Oct 28, 2008, at 12:30, Jean-Nicolas Jolivet wrote:

One more thing, you mentioned the term "KVO Compliance"... I understand that this means to send the proper notifications when a change to my property has been made...

But: would it be considered bad practice if my file class does have a property that is used just for displaying purpose (For example, by combining other properties (fileName, extension, size) into a nicely formatted string) to display in a tableView... by bad practice I mean: I know that this property is only used for display purpose and will never be edited... but will be modified when other properties (filePath etc..) have been modified?

No, it's not bad practice to have a "derived" property for display purposes. That's basically what -[NSObject description] is, for example, and that's a *really* important property.


Would it mean that this property is not "KVO compliant" and if so, is it a problem? Assuming I know it should never be "observed" (i.e. it will never be modified directly, only by modifying other properties)...

Not sure what this means. "Observed" doesn't mean modifiable. It means some other object is watching for change notifications. In particular, if you bind something to your derived property (which is what you're doing in your table view), the property gets observed by the binding, and so must be KVO compliant.


basically from your post I understand that.. technically, it's not a problem to do it like that, but... would it be considered bad practice since the property is not KVO compliant? and if so, is it even possible to make it KVO compliant?

There's at least 2 ways. If you have a setter for "filePath", you can do this:


- (void) setFilePath: (NSString*) newValue {
[self willChangeValueForKey: @"fileName"];
filePath = newValue; // plus retain/release code too, if you aren't using garbage collection
[self didChangeValueForKey: @"fileName"];
}


Or you can have it happen automatically:

	@implementation File
	+ (NSSet*) keyPathsForValuesAffectingFileName {
		return [NSSet set withObject: @"filePath"];
	}
	...

(The latter is the Leopard way. For Tiger, you use 'setKeys:triggerChangeNotificationsForDependentKey:' instead.)


_______________________________________________

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: Binding question
      • From: Quincey Morris <email@hidden>
    • Re: Binding question
      • From: Jean-Nicolas Jolivet <email@hidden>
References: 
 >Binding question (From: Jean-Nicolas Jolivet <email@hidden>)
 >Re: Binding question (From: Quincey Morris <email@hidden>)
 >Re: Binding question (From: Jean-Nicolas Jolivet <email@hidden>)

  • Prev by Date: Re: Code signing validation
  • Next by Date: Re: ASL & Unicode in Xcode's Console
  • Previous by thread: Re: Binding question
  • Next by thread: Re: Binding question
  • Index(es):
    • Date
    • Thread