• 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: Reporting errors from key-value-coding accessors
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reporting errors from key-value-coding accessors


  • Subject: Re: Reporting errors from key-value-coding accessors
  • From: Dustin Voss <email@hidden>
  • Date: Fri, 19 Aug 2005 15:55:50 -0700

On 19 Aug 2005, at 12:53 PM, Mark Alldritt wrote:

Hi,


In my application I have a long list of KVC accessor functions that
need to
potentially report errors.  If the accessor is called from
bindings, I'm not
at all sure how to report an error.


Use KVC validation methods: <http://developer.apple.com/documentation/Cocoa/Conceptual/ KeyValueCoding/Concepts/Validation.html>


Thanks for the pointer. This is fine in as far as it goes, but there are
still problems which this does not address:


1) Cocoa Scripting does not appear to use this
2) It does not help with getters that need to signal errors
3) What if a pre-flight validation model does not fit your application?

1) For Cocoa Scripting, the best option is to use a parallel set of Cocoa Scripting KVC accessors. This is usually necessary anyway, as the semantics of scripted mutation/access can differ from UI or internal mutation/access, and separate accessors are the only way to enforce read-only properties (although you can mark a property as read-only in the dictionary, Cocoa Scripting does not check that).


The parallel accessor just calls the primitive accessor and may also perform validation using the validation methods.

To report an error from a scripting accessor, you can call [NSScriptCommand currentCommand] and call -setScriptErrorNumber: and - setScriptErrorString:.

Ask on the applescript-implementors list if you want a more in-depth discussion.

2) Getters that may find an error that the UI should display to the user should make an NSError and display it using NSApp or NSWindow's facilities. See <http://developer.apple.com/documentation/Cocoa/ Conceptual/ErrorHandlingCocoa/index.html>.

Keep the validation logic in -validate<key>:error:. There nothing stopping the getter from calling this method to make sure everything is in order. You may want to override -valueForKey: if you are doing this on a large scale.

3) Bindings can validate input immediately, and there are control- specific techniques to do the same thing without bindings.

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Reporting errors from key-value-coding accessors
      • From: Mark Alldritt <email@hidden>
References: 
 >Re: Reporting errors from key-value-coding accessors (From: Mark Alldritt <email@hidden>)

  • Prev by Date: Re: (id) sender
  • Next by Date: Re: turning the focus ring off on 10.2
  • Previous by thread: Re: Reporting errors from key-value-coding accessors
  • Next by thread: Re: Reporting errors from key-value-coding accessors
  • Index(es):
    • Date
    • Thread