2013-07-15 42 views
0

我想從實體中提取對象,其實體數據庫中提供的startDateendDate大於日期 。我目前正在使用IN謂詞如下NDSredicate with IN for NSDate

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K IN %@ OR %K in %@", kEntityEventAttributeStartDate, inArray, kEntityEventAttributeEndDate, inArray]; 
request setPredicate:predicate]; 

但我認爲它會檢查等於日期在哪裏,我想這日期是更大的。

任何想法如何實現這與NSPredicate

在此先感謝。

+0

你的意思是「startDate大於數組中的日期」?它應該大於數組中的所有值嗎? –

+2

爲什麼你有一個日期數組來檢查,如果'startDate'和'endDate'必須大於它們全部?難道你不能只用最大的日期,並用'%K>%@'與它比較嗎? – Greg

+0

並非所有值都大於至少一個值 –

回答

0

我通過創建一個具有開始日期和結束日期的謂詞來解決它,我查詢模型以獲取所提供的範圍之間的所有日期。

感謝您的幫助和建議。

1

你可以先排序日期排列,如:

NSArray *dateArraySorted = [inArray sortedArrayUsingDescriptors:[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"Date" ascending:YES]]]; 

//Select the smallest date - if the date is greater than this then there is no point in checking against others and vice-versa. 
NSDate *smallestDate = dateArraySorted[0]; 

從這裏,我想你知道如何創建謂詞。