Core Data Save Error (NSValidationErrorKey, Cocoa error 1570) saving NSDate

旧巷老猫 提交于 2019-11-28 19:05:14
Michael A.

The cocoa error 1570 means that mandatory fields are not filled in. In this case, your have two attribues that are nil : Voedsel and datum.

I see in your code :

newDaglijst.Voedsel = geselecteerdVoedsel;
newDaglijst.datum = selDatum;

Check that geselecteerdVoedsel and selDatum are not nil or that they are overreleased and finish to be nil. If they are optional data (but I don't think so), define them as optional in coredata.

Hope this help,

as Michael A said. Check your attributes value are not nil. There are 2 alternatives to get rid of these error. Case 1:If 2 attributes are Required

If the 2 attributes are required attributes then it is mandatory to check the values you are passing are not nil,It may happens sometimes,If u want to get out of these error u have to give default values for those attributes in attributes inspector of your Entity in data Model

Case 2: Set those attributes to optional in attribute inspector by selecting the check mark of optional.

Me too struggled for days to know these error. Hope it helps someone.

Your logging would look like this:

Fatal error: 'try!' expression unexpectedly raised an error: 
Error Domain=NSCocoaErrorDomain Code=1560 "(null)" UserInfo={NSDetailedErrors=(
...

It means you have an uncommitted change for one (or more) property of a entity, in which you told it is NOT optional, but you left it optional.

To find out which entity you failed to set value for a property, look for this in your logging:

UserInfo={NSValidationErrorObject=<YOURENTITYISHERE: ...>

To find out the property, search for:

NSValidationErrorKey=YOURPROPERTYISHERE

Somewhere in your code you forget to set a value for that property for the given entity.

I had this issue when I copied entities from other xcdatamodeld file. They lost inverse attributes, so that was the reason.

Not really related with date, but with the error, I share it as this question has more views:

In my case, I was setting a BOOL property directly as YES or NO, but you should use

NSNumber numberWithBOOL

in order to make it work.

To reinforce Michael's answer, you can check your Entity properties in the inspector. One of your items may be accidentally considered Optional, or not. Or, if you're like me, your "Delete Rule" might have been set to "Nullify", which made my Entity's relationship property Nil at runtime. Because my object-to-be-deleted had a One-To-Many relationship with some other objects, it prevented the parent objects from being deleted. Changing it to Cascade solved the problem.

Entity Inspector - Delete Rule

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!