【发布时间】:2019-10-16 00:38:12
【问题描述】:
我是 iOS 开发的新手,你能帮我解决一下你的 bug。谢谢你的提前。
未捕获的异常“NSUnknownKeyException”,原因: '[setValue:forUndefinedKey:]: 此类与键 Project1 的键值编码不兼容。'
let context = appdelegate.persistentContainer.viewContext
let proj = Project()
let arrProj = dic.object(forKey: "Projects") as! NSArray
for n in 0..<arrProj.count {
let subDic = arrProj.object(at: n) as! NSDictionary
let item = ProjectItem(dict: subDic)
proj.arrProjs.append( item )
let projects = NSEntityDescription.entity(forEntityName: "Projects", in: context)
projects?.setValue(item.Project, forKey: "project1")
projects?.setValue(item.Project2, forKey: "project2")
projects?.setValue(item.ID, forKey: "projectid")
projects?.setValue(item.radius, forKey: "radius")
projects?.setValue(item.GeofenceType, forKey: "geo_Type")
projects?.setValue(item.Geofence, forKey: "geofence")
projects?.setValue(item.Coordinates, forKey: "coordinates")
}
【问题讨论】:
-
这个错误什么时候出现?
-
项目有 NSObject 类?
-
谢谢您的回复,我正在使用CoreData数据库,在节省时间的同时,遇到这个问题您能帮帮我吗
-
@YogeshPatel Project 是另一个类,仍然可以正常工作,但让 projects = NSEntityDescription.entity(forEntityName: "Projects", in: context) projects?.setValue(item.Project, forKey: "project1" ) 唯一的问题
-
请在 xib 或 storyboard 中检查您的网点,确保所有连接完美。请告诉我?