• 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: key-value validation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: key-value validation


  • Subject: Re: key-value validation
  • From: mmalcolm crawford <email@hidden>
  • Date: Tue, 18 Nov 2003 21:59:33 -0800

On Nov 18, 2003, at 6:59 PM, Matthew Johnson wrote:

I noticed the key-value validation docs specify "an implementation of
-set<Key>: for a property should never call the validation methods."
Is this with the intention that -validate<Key>:error: is always called
prior to the call to -set<Key>? I assume this is because the
controller layer needs to separate validation from actual setting of a
value.

The controller layer doesn't *need* to, but the function of validation is separate from updating. As Mark Piccirelli put it, "How to validate is a model decision, when to validate is a UI decision."
You don't want to validate every time you set a value. Moreover: If you call the validation method during the setter, on return you have no means of detecting any validation failure or retrieving any error; and there's no way of getting hold of any modified value (except subsequently using the getter).

If so, is it sensible for a model to implement a convenience
method -set<Key>IfValidated:error: to take care of validation and
setting the value if validation is successful? This seems like the
right approach so that code that is directly using the model rather
than going through kvc would have a nice clean interface...

Umm, what's wrong with directly using the nice clean interface provided by the validation methods you implement in the model...? You call the validation method if you want, otherwise you don't.

mmalc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >key-value validation (From: Matthew Johnson <email@hidden>)

  • Prev by Date: Re: XCode and tabbing
  • Next by Date: Re: Kiosk Memory Cards and Elegant Ejecting
  • Previous by thread: key-value validation
  • Next by thread: Dynamically Generating GUI forms from an XML file?
  • Index(es):
    • Date
    • Thread