Re: Validating a non-optional transient Core Data property - it can be erased?!
Re: Validating a non-optional transient Core Data property - it can be erased?!
- Subject: Re: Validating a non-optional transient Core Data property - it can be erased?!
- From: Quincey Morris <email@hidden>
- Date: Wed, 12 Nov 2008 15:33:23 -0800
On Nov 12, 2008, at 13:31, Arthur C. wrote:
In my Core Data database I have a property called 'target' (double),
which is transient and required (i.e. 'non-optional' in the model).
It is dependent on another variable 'color'; so for each color there
is a 'target'. As I want to show only the target for the selected
color, I use this transient variable. It is used as well to set a
new target (from the table view) for the selected color.
In the model I have imposed a minimum, maximum and default value for
'target', and the table column is set to validate immediately. This
works correctly. However, the feedback in the validation sheet is
rather minimal.
So, first question: how can I change the validation message, to
include e.g. required range etc.?
Another thing is, I have found that I can erase the value in the
table view, without a validation error getting triggered! A nil-
value is not acceptable. The easiest solution I've found is just to
make it persistent (non-transient). But I think 'non-optional'
should mean 'required', meaning the value should never be nil...
especially since I gave a min, max and default value.
Is there a better way to do this while keeping the variable transient?
I think the answer is the same for both your questions:
http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/Articles/cdValidation.html#/
/apple_ref/doc/uid/TP40004807-SW2
In other words, write your own validation method for the 'target'
property. If you do that, you can check for a nil value, and also you
can return any error message you want. (Pay careful attention to what
it says about validation *instead of* versus validation *as well as*
Core Data's other validation mechanisms.)
There's also a way of localizing the built-in error messages, which
may be another solution to your first question if you just want to
vary the wording a bit:
http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/Articles/cdUsingMOM.html#/
/apple_ref/doc/uid/TP40005190-SW13
As to whether a nil value *ought* to fail built-in validation for non-
optional transient properties, I don't know the answer. It seems like
it ought to, but various things behave a little differently for
transient properties. It may be worth filing a bug report about, if
you don't get an answer here.
_______________________________________________
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