2009-07-08 5 views
1

CoreData 정보를 탐색하고 NSTimeInterval 내에있는 createdAt (NSDate로 내 객체의 일부)가있는 객체를 찾는 방법을 찾으려고합니다. 어떻게 설정합니까?CoreData - 시간 범위 (NSTimeInterval)로 형식화 된 NSPredicate

난에서 문서에보고했습니다 http://developer.apple.com/documentation/Cocoa/Conceptual/Predicates/predicates.html

그러나 나는 거기에 아무것도 발견 아니에요.

두 개의 타임 스탬프를 만들고 SQL 사이에 사용해야합니까?

도움이 될 것입니다.

답변

0

우선 NSDate가 NSTimeInterval 내에 있는지 확인하는 것은 의미가 없습니다. NSTimeInterval은 위치가 아니라 시간 길이를 지정하기 때문입니다. 대신, 간격의 시작과 끝을 지정하는 두 개의 별도 NSDate를 사용하려고합니다.

다음과 같이 표시됩니다 (beginningTime 및 endTime은 NSDates 임).

NSFetchRequest *request = [[NSFetchRequest alloc] init]; 
request.entity = [NSEntityDescription entityForName:@"YourEntityName" inManagedObjectContext:yourContext]; 
NSPredicate *beginningPredicate = [NSPredicate predicateWithFormat:@"createdAt >= %@", beginningTime]; 
NSPredicate *endPredicate = [NSPredicate predicateWithFormat:@"createdAt <= %@", endTime]; 
request.predicate = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects:beginningPredicate, endPredicate, nil]]; 
NSArray *results = [yourContext executeFetchRequest:request error:NULL];