documentation에는 관리되는 개체가 아닌 단순한 값만 검색하는 방법에 대한 예제가 있습니다. 별칭과 함수를 사용하여 계산 된 값만 검색하는 SQL을 많이 기억합니다. 그래서, 실제로 꽤 귀찮은 물건. 기록의 무리에서 최소 날짜를 얻으려면,이 맥에 사용됩니다iPhone에서 이와 같은 표현식을 사용하여 가져 오기 요청을 수행하는 방법은 무엇입니까?
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Event" inManagedObjectContext:context];
[request setEntity:entity];
// Specify that the request should return dictionaries.
[request setResultType:NSDictionaryResultType];
// Create an expression for the key path.
NSExpression *keyPathExpression = [NSExpression expressionForKeyPath:@"creationDate"];
// Create an expression to represent the minimum value at the key path 'creationDate'
NSExpression *minExpression = [NSExpression expressionForFunction:@"min:" arguments:[NSArray arrayWithObject:keyPathExpression]];
// Create an expression description using the minExpression and returning a date.
NSExpressionDescription *expressionDescription = [[NSExpressionDescription alloc] init];
// The name is the key that will be used in the dictionary for the return value.
[expressionDescription setName:@"minDate"];
[expressionDescription setExpression:minExpression];
[expressionDescription setExpressionResultType:NSDateAttributeType];
// Set the request's properties to fetch just the property represented by the expressions.
[request setPropertiesToFetch:[NSArray arrayWithObject:expressionDescription]];
// Execute the fetch.
NSError *error;
NSArray *objects = [managedObjectContext executeFetchRequest:request error:&error];
if (objects == nil) {
// Handle the error.
}
else {
if ([objects count] > 0) {
NSLog(@"Minimum date: %@", [[objects objectAtIndex:0] valueForKey:@"minDate"];
}
}
[expressionDescription release];
[request release];
니스,하지만 I -하지만 아이폰 OS가 min:
기능을 지원하지 않는 것으로 나타났다 NSExpression -expressionForFunction:arguments:에 깊은 모양을 가진.
음, 아마도 iPhone의 이러한 종류의 기능에 고유 기능을 사용하는 멋진 방법이 있을까요? 내가 이미 염려하고있는 점은지도에서 계산 된 목표 거리 (위치 기반 자료)를 기반으로 표를 정렬하는 방법입니다.