0
我有以下數據模型:核心數據謂詞:在NSDate上有活動的所有組?
Group(name, color, activities*) // one group may have many activities
Activity(startTime, endTime, location, Group*) // startTime and endTime are NSDate, group is an inverse relationship
所以如果我想要得到誰擁有這對指定的NSDate,說theTime,我應該構建什麼樣的斷言至少一個活動的所有組?
我的想法:
- 首先獲得所有活動
- 然後把它們組爲一組,以消除重複的組
- 轉換設置爲一個數組
這樣:
[NSPredicate predicateWithFormat:@"%@ >= startTime AND %@ <= endTime", theTime]
取活動的一個數組,那麼:
for (Activity *activity in activities)
{
[theSet add:activity.group];
}
,所以我得到了有theTime至少一個活動的獨特組的陣列?
是否有任何其他方式只做一個沒有後處理的提取?
謝謝!
編輯:
我可以這樣做:
[NSPredicate predicateWithFormat:@"%@ >= activities.startTime AND %@ <= activities.endTime", theTime]
???