假设我们有 2 个实体:
- 人(姓名,年龄,..)
-房子(颜色)
house.addToPeople (newPeople)
我们为每个房子记录了几次数据
我们想让房子里的所有人都染成蓝色
我们如何获取这个?
我试过这段代码,但它得到了所有人
let appD = UIApplication.shared.delegate as! AppDelegate
let context = appD.persistentContainer.viewContext
let peopleFetch = NSFetchRequest<NSFetchRequestResult>(entityName: "People")
let houseFetch = NSFetchRequest<NSFetchRequestResult>(entityName: "House")
houseFetch.fetchLimit = 1
houseFetch.predicate = NSPredicate(format: "color = %@", "blue")
...
let res = try? context.fetch(peopleFetch)
let resultData = res as! [People]
这个怎么做 ?