实体用户不符合密钥“ dateEndSubscription”的密钥值编码标准。 [英] The entity User is not key value coding-compliant for the key "dateEndSubscription"
问题描述
我在xcdatamodeld中有一个包含3个实体的快捷项目:Access,CustomerInfo和User。我试图在用户中单独保存dateEndSubscription。当我尝试保存时,出现以下错误:由于未捕获的异常'NSUnknownKeyException'而终止应用程序,原因:'[setValue:forUndefinedKey:]:实体User不符合键 dateEndSubscription的键值编码要求。
I have a swift project with 3 entities in my xcdatamodeld: Access, CustomerInfo and User. I am trying to save the dateEndSubscription separately in the User. When I am trying to save , I get error as : Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: the entity User is not key value coding-compliant for the key "dateEndSubscription".' Anyone please help to solve it in swift4.
推荐答案
json消息包含密钥 dateEndSubscription $ c $ c>,但您的用户实体中的属性命名为
dateEnd
,因此它们不匹配。
The json message contains the key dateEndSubscription
but the attribute in your User entity is named dateEnd
so they doesn’t match.
A在您的 saveUser
方法中解决此问题的几种方法
A few options to solve this in your saveUser
method
更改 API.DateEnd
到 dateEnd
,但也许可以推断出json消息的解码。
Change API.DateEnd
to dateEnd
but maybe that will infer with the decoding of the json message.
不要使用API密钥,但使用硬编码属性名称
Don't use API key but instead hardcode attribute name
user.setValue(dateEnd, forKey: "dateEnd")
最后直接使用User类的属性
and lastly use the property of the User class directly
user.dateEnd = dateEnd
您还需要更改 saveCustomerInformation
,因为您正在使用 User
也在那里反对,尽管不清楚原因。
You need to change saveCustomerInformation
as well since you are working with a User
object there as well although it's unclear why.
这篇关于实体用户不符合密钥“ dateEndSubscription”的密钥值编码标准。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!