-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Hi, it's me, the Olaf from Stackoverflow.
You are raising an interesting point there:
The workaround works fine when you're starting a new project. But users of the framework who are already using Core Data probably have constraints specified in the model and adding my framework would mean moving all of that to the validation method.
A sightly different way would be to read the model and to extract the validation constraints. If the model does not contain any limits, i.e. the user of the framework did not set any limits, then the framework can set limits for the entity. Either limits are will be validated agains the attribute.
Basically what the code should be doing is to override validateValue:forKey:error:. It obtains the limits from the validationPredicates in the model. If no validationPredicates are defined in the model then the entity has its own validationPredicates defined in code.
The validationPredicates are applied to the value. If there is a validation mismatch then an error is generated. A bit of cosmetics is merging the attribute name (key) and the limit value expectedLimit into the error message <key> can't be more than <expectedLimit>
There is no change to the view.
I have hacked something together to demonstrate above. I will try to add a pull request., something I have never done here before, so please be patent with me.