Core Data ignoring validation constraint
Core Data ignoring validation constraint
- Subject: Core Data ignoring validation constraint
- From: Tom Harrington <email@hidden>
- Date: Mon, 09 Jan 2012 11:47:09 -0700
I have a data model where one of the string attributes has both a min
and max length validation requirement. At run time though, only the
max length constraint seems to exist. Violating the min length
constraint doesn't cause validation failures, whether using
-validateForInsert: or -validateValue:forKey:error: For example:
NSString *tooShortName = @"a";
NSError *validationError = nil;
[category validateValue:&tooShortName forKey:@"name" error:&validationError];
At this point validationError is still nil. Continuing:
[category setValue:tooShortName forKey:@"name"];
[category validateForInsert:&validationError];
...still nil.
I suspected that the data model GUI might be lying to me so I looked
at the model file directly (glad it's XML) and found this for the
attribute:
<attribute name="name" attributeType="String" minValueString="10"
maxValueString="100" syncable="YES"/>
So, both constraints are in the model file. They don't both get loaded
at run time though:
(gdb) po [[[[category entity] attributesByName] objectForKey:@"name"]
validationPredicates]
<__NSArrayM 0x897bcd0>(
length <= 100
)
I tried creating a new project to test this and got the same thing
immediately. Is there some additional step I've missed?
I'm using Xcode 4.2.1 on Mac OS X 10.7.2; results are the same in the
simulator and on an iPhone 4s running iOS 5.0.1.
--
Tom Harrington
email@hidden
AIM: atomicbird1
_______________________________________________
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