解决:Thread 1:[<*>setValue:forUndefinedKey]:this class is not key value coding-compliant for the key *

问题:运行程序崩溃,报错:“Thread 1: [<*> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key **.”,截图如下: 


原因:在kvc映射中,映射的字段名和个数不一致导致的。


解决方案:复写“func setValue(_ value: Any?, forUndefinedKey key: String)”方法。

​​​​​​​

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
给下面每一行代码给上注释#include "pch.h" #include "FinBudgetFlowManager.h" int FinBudgetFlowManager::C(double _value, time_t _time, CString _remark, FlowType _type) { FinBudgetFlow* pFBD = new FinBudgetFlow(); pFBD->setValue(_value); pFBD->setTime(_time); pFBD->setRemark(_remark); pFBD->setType(_type);; this->FlowMap.insert(std::map<int, FinBudgetFlow*>::value_type(this->getSize(), pFBD)); return this->getSize()-1; } bool FinBudgetFlowManager::U(int _index, double _value, time_t _time, CString _remark, FlowType _type){ std::map<int, FinBudgetFlow*>::iterator iter; iter = this->FlowMap.find(_index); if (iter != this->FlowMap.end()) { delete iter->second; iter->second = NULL; this->FlowMap.erase(iter); FinBudgetFlow *pFBD = new FinBudgetFlow(); pFBD->setValue(_value); pFBD->setTime(_time); pFBD->setRemark(_remark); pFBD->setType(_type); this->FlowMap.insert(std::map<int, FinBudgetFlow*>::value_type(_index, pFBD)); return true; } else { throw _index; } } FinBudgetFlow* FinBudgetFlowManager::R(int _index) { std::map<int, FinBudgetFlow*>::iterator iter; iter = this->FlowMap.find(_index); if (iter != this->FlowMap.end()) { return iter->second; } else { throw _index; } } bool FinBudgetFlowManager::D(int _index) { std::map<int, FinBudgetFlow*>::iterator iter; iter = this->FlowMap.find(_index); if (iter != this->FlowMap.end()) { delete iter->second; iter->second = NULL; //防止野指针这一步是否真的需要? this->FlowMap.erase(iter); return true; } else { throw _index; } } int FinBudgetFlowManager::getSize() { return FlowMap.size(); }
最新发布
06-10
//引入预编译头文件 #include "pch.h" //引入头文件"FinBudgetFlowManager.h" #include "FinBudgetFlowManager.h" //定义函数C,返回类型为int,参数为value,time,remark和type int FinBudgetFlowManager::C(double _value, time_t _time, CString _remark, FlowType _type) { //创建一个新的FinBudgetFlow对象 FinBudgetFlow* pFBD = new FinBudgetFlow(); //设置新对象的value pFBD->setValue(_value); //设置新对象的time pFBD->setTime(_time); //设置新对象的remark pFBD->setRemark(_remark); //设置新对象的type pFBD->setType(_type);; //将新对象插入到FlowMap中 this->FlowMap.insert(std::map<int, FinBudgetFlow*>::value_type(this->getSize(), pFBD)); //返回FlowMap的大小减一 return this->getSize()-1; } //定义函数U,返回类型为bool,参数为index,value,time,remark和type bool FinBudgetFlowManager::U(int _index, double _value, time_t _time, CString _remark, FlowType _type){ //定义一个迭代器 std::map<int, FinBudgetFlow*>::iterator iter; //在FlowMap中查找index iter = this->FlowMap.find(_index); //如果找到了 if (iter != this->FlowMap.end()) { //删除原有对象 delete iter->second; iter->second = NULL; //从FlowMap中删除原有对象 this->FlowMap.erase(iter); //创建一个新的FinBudgetFlow对象 FinBudgetFlow *pFBD = new FinBudgetFlow(); //设置新对象的value pFBD->setValue(_value); //设置新对象的time pFBD->setTime(_time); //设置新对象的remark pFBD->setRemark(_remark); //设置新对象的type pFBD->setType(_type); //将新对象插入到FlowMap中 this->FlowMap.insert(std::map<int, FinBudgetFlow*>::value_type(_index, pFBD)); //返回true return true; } //如果没有找到 else { //抛出异常 throw _index; } } //定义函数R,返回类型为FinBudgetFlow*,参数为index FinBudgetFlow* FinBudgetFlowManager::R(int _index) { //定义一个迭代器 std::map<int, FinBudgetFlow*>::iterator iter; //在FlowMap中查找index iter = this->FlowMap.find(_index); //如果找到了 if (iter != this->FlowMap.end()) { //返回找到的对象 return iter->second; } //如果没有找到 else { //抛出异常 throw _index; } } //定义函数D,返回类型为bool,参数为index bool FinBudgetFlowManager::D(int _index) { //定义一个迭代器 std::map<int, FinBudgetFlow*>::iterator iter; //在FlowMap中查找index iter = this->FlowMap.find(_index); //如果找到了 if (iter != this->FlowMap.end()) { //删除对象 delete iter->second; iter->second = NULL; //从FlowMap中删除对象 this->FlowMap.erase(iter); //返回true return true; } //如果没有找到 else { //抛出异常 throw _index; } } //定义函数getSize,返回类型为int int FinBudgetFlowManager::getSize() { //返回FlowMap的大小 return FlowMap.size(); }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值