Re: How to Validate CoreData attribute value for uniqueness
Re: How to Validate CoreData attribute value for uniqueness
- Subject: Re: How to Validate CoreData attribute value for uniqueness
- From: Jerry Krinock <email@hidden>
- Date: Sun, 31 Aug 2014 16:09:40 -0700
Hello, Motti. I read your post. All 600+ words :)
> On 2014 Aug 30, at 03:58, Motti Shneor <email@hidden> wrote:
> I would gladly settle on a UI-only validation (meaning, something that would validate a text field upon end-edit-session=
I would pursue that.
> but I don't know how to hook this on a bound-to-model field
I think you are saying that you are using Cocoa Bindings (must be an OS X app). Indeed, coupling the data model tightly to the view, which is the essence of Cocoa Bindings, does not leave any hooks for validation. That may be why Core Data offers it. But as you’ve seen, it can be problemsatic in real life cases.
Consider one of these two alternatives…
• Interpose a controller between your model and your view, which will validate user input before telling the data model. Either don’t use Cocoa Bindings, or else expose a model-side binding in your controller and bind that with your managed object context.
• Implement your validation in a controller, observing as a bystander. Immediately send your managed object context an -undo whenever a validation error is detected.
Either way might present its own challenges, but at least this code is under your control.
Or maybe reading these ideas will inspire someone else to suggest something better :)
_______________________________________________
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