Базовые Данные: попытка найти минимальную дату атрибута в объекте

Я пытаюсь найти самую старую дату в конкретном атрибуте в Базовых Данных. Я нашел пример в Базовом Руководстве по программированию Данных, которое подразумевает делать точно, что, но продолжают получать нераспознанную выбранную ошибку, когда я выполняю его.

Мой код (только с минимальными изменениями от Примера Apple):

NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Session" inManagedObjectContext: ctx];
[request setEntity:entity];

// Specify that the request should return dictionaries.
[request setResultType:NSDictionaryResultType];

// Create an expression for the key path.
NSExpression *keyPathExpression = [NSExpression expressionForKeyPath:@"startedAt"];

// 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 = [ctx executeFetchRequest:request error:&error];

И ошибка:

-[NSCalendarDate count]: unrecognized selector sent to instance ...

Который является странным, учитывая, что 1) NSCalendarDate удерживается от использования и 2) я определенно не называю количество.

Любая справка больше всего ценилась бы!

8
задан AndrewO 10 May 2010 в 21:39
поделиться

1 ответ

Почему бы просто не добавить дескриптор сортировки для сортировки по startDate по возрастанию, и тогда только запрос на выборку вернет 1 объект?

15
ответ дан 5 December 2019 в 11:23
поделиться
Другие вопросы по тегам:

Похожие вопросы: