>From: [EMAIL PROTECTED]>To: [email protected]>Subject: Validating a 
>non-optional transient Core Data property - it can be erased?!>Date: Wed, 12 
>Nov 2008 22:31:02 +0100>

>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?> 
> (Pay careful attention to what  > it says about validation *instead of* 
> versus validation *as well as*  > Core Data's other validation mechanisms.)
Yes, I have found that I should not do it both. That is, if I check also in 
code on maximum/minimum, an error message 'multiple validation errors' will 
come up. 
 
>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 
 
Well, that turns out to be complicated... I have to retrieve the validation 
predicates for max, min from the model:
 
 NSEntityDescription * recipeEntity = [NSEntityDescription entityForName: 
@"Recipe" inManagedObjectContext: [[NSApp delegate] managedObjectContext]];  
NSAttributeDescription * targetDescription = [[recipeEntity propertiesByName] 
valueForKey: @"target"]; NSArray * validationPredicates = [targetDescription 
validationPredicates];
after which the predicates need to be parsed in order to find which is the max 
/ min predicate. Then, the custom error message has to be fed to the managed 
object model's localizationDictionary, which I don't fully understand... The 
following code does not work:
 
 NSManagedObjectModel * model = [[NSApp delegate] managedObjectModel]; 
NSMutableDictionary * localizedDict = [NSMutableDictionary dictionary];
 for (unsigned int i = 0; i < [validationPredicates count]; i++) {  
NSComparisonPredicate * predicate = [validationPredicates objectAtIndex: i];  
NSString * description = [predicate description];  double value = [[[predicate 
rightExpression] constantValue] doubleValue];    if ( [description hasPrefix: 
@"SELF >"] )  {   minimumTarget = value;   id validationWarning = 
[[targetDescription validationWarnings] objectAtIndex: i];   [localizedDict 
setValue: @"Test string 123" forKey: [NSString stringWithFormat: 
@"ErrorString/%@", validationWarning]];   [model setLocalizationDictionary: 
localizedDict];     } 
 }
 
Any ideas on how this can be done in a *simpler* way?
 
 
Thanks so far,
Arthur
 
 
 
> >Thanks in advance,>Arthur    



Express yourself instantly with MSN Messenger! MSN Messenger
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to