Core Data: Keypath Error Not Found in Entity

后端 未结 4 1090
陌清茗
陌清茗 2021-02-19 02:05

Could any one tell me what\'s the wrong with this code? It raises the following error and cause application to crash:

reason: \'keypath Studies.patients.Patient         


        
4条回答
  •  萌比男神i
    2021-02-19 02:52

    Firstly, since your fetch entity is Studies you don't include it in the predicate because the Studies objects are the ones receiving the predicate test in the first place. So your predicate should be at least just:

    patients.PatientName == %@
    

    However, by convention, patients would indicate a to-many relationship. If so, that means that the actual value of patients is a set of (presumably) Patient objects. As such you can't ask a set for an attribute value as above: Instead you have to ask for a new set of all object in the set that match the predicate. Use the ANY or All operator like so:

    ALL patients.PatientName == %@
    

    I would add that by convention all attribute and relationship names start with lower case letters so if PatientName is an attribute it should be patientName.

提交回复
热议问题