开发者

How to properly use CoreData validation & error framework?

I've created a model in Xcode, and for various attributes I have minimum & maximum values defined and that are enforced by coreData at runtime.

I'm using NSManagedObject validateValue:forKey:error to check 开发者_如何学JAVAfor user input values.

I was a bit disappointed to see that the localized error message is not specific, and I get a "The operation couldn't be completed. (Cocoa error 1620)" for too small values and a "The operation couldn't be completed. (Cocoa error 1610)" for too large values.

It's written in the coreData documentation that "you can localize most aspects of a managed object model, including entity and property names and error messages". Unfortunately it's not very detailed on how you implement it for error messages.

So How do you customize error message ? How do you localize them ? Is it possible to customize it in a way where it will mentioned the reference value ex: "Value should be lower than %@" or "Value should be higher than %@" ?


To customize the errors as you want, you will need to implement custom NSManagedObject subclasses and then implement the validation methods for each attribute to return the errors you wish.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜