I'd like to play around with attribute value validation, but the documentation is pretty empty on this. Maybe there's an good article or tutorial out there?
+1
A:
Here is a fairly common validation to ensure you don't get nonsensical dates put into a timeStamp.
- (BOOL)validateTimeStamp:(id *)valueRef error:(NSError **)outError
{
NSDate *testDate=(NSDate *) valueRef;
if ([testDate compare:self.minimumTimeStamp]==NSOrderedAscending) {
// generate and return error so you can set a proper date
}
return YES;
}
TechZen
2010-06-11 13:17:07
Is Core Data calling this validator automatically, or would I have to call that manually before trying to set the value?
dontWatchMyProfile
2010-06-11 14:20:11
If the method exist in with the proper name, it is called automatically upon an attempt to save the context. I usually prefer to manually call validate at the time the attribute is set so it can be corrected immediately. That is not always feasible.
TechZen
2010-06-11 16:59:57