Iphone 核心数据关系
假设您的数据模型如下所示:Iphone 核心数据关系,iphone,cocoa-touch,core-data,Iphone,Cocoa Touch,Core Data,假设您的数据模型如下所示: /-----------------------\ /-----------------------\ | Patient | | Medication | |-----------------------| |-----------------------| | firstName | | startOn
/-----------------------\ /-----------------------\
| Patient | | Medication |
|-----------------------| |-----------------------|
| firstName | | startOn |
| lastName | | endOn |
|-----------------------| |-----------------------|
| medications | <<-\ | |
| | \->> | patients |
\-----------------------/ \-----------------------/
如何实现mostrecentlycompletedmediation
方法
谢谢 这实际上不是一个核心数据问题,而是一个可可收集问题。我将对
药物
关联集进行排序。假设患者=>药物与多种药物的关联称为药物
:
Patient *myPatient;
NSSet *medications = [myPatient medications];
Medication *mostRecent = [medications sortedArrayUsingDescriptors:[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"endOn" ascending:YES]]]
lastObject
];
天哪,曼廷戈!感谢上帝,我为那场电影表演跳了起来!!!说真的,谢谢你,让事情变得更清楚了。真不敢相信我以前没有看到这一点。@比尔,你可以很容易地把它分成更多的行(Xcode的编辑器,就像一个好的LISP编辑器,可以在一个混乱调用中正确缩进),但在SO编辑器中排列东西是一件痛苦的事情……希望患者没有很多药物,药物也没有很多患者^^
Patient *myPatient;
NSSet *medications = [myPatient medications];
Medication *mostRecent = [medications sortedArrayUsingDescriptors:[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"endOn" ascending:YES]]]
lastObject
];