How to use CoreData authentication and error authentication scheme?

I created a model in Xcode, and for various attributes I have defined minimum and maximum values ​​and which are executed by coreData at runtime.

I am using NSManagedObject validateValue: forKey: error to validate user input values.

I was a little disappointed to see that the localized error message is not specific, and I get "Operation could not be completed. (Cocoa error 1620)" for values ​​too small and "Cannon operation (Cocoa error 1610)" for values ​​too large .

The coreData documentation says that "you can localize most aspects of the managed object model, including object and property names and error messages." Unfortunately, it does not describe in very detail how you implement it for error messages.

So how do you configure the error message? How do you localize them? Is it possible to configure it to mention the ex reference value: "The value must be lower than% @" or "The value must be higher than% @"?

+3
source share
1 answer

To set up the necessary errors, you need to implement custom subclasses of NSManagedObject, and then implement validation methods for each attribute to return the errors you need.

0

Source: https://habr.com/ru/post/1750317/


All Articles