Estoy tratando de encontrar la fecha más antigua en un atributo particular en Datos centrales. He encontrado an example in the Core Data Programming Guide que pretende hacer exactamente eso, pero sigo obteniendo un error seleccionado no reconocido cuando lo ejecuto.Datos principales: tratando de encontrar la fecha mínima para un atributo en una entidad
Mi código (con sólo cambios mínimos del Ejemplo de 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];
y el error:
-[NSCalendarDate count]: unrecognized selector sent to instance ...
lo cual es extraño teniendo en cuenta que 1) NSCalendarDate es obsoleto y 2) I' Definitivamente no estoy llamando a contar.
¡Cualquier ayuda sería muy apreciada!
¿Está "startedAt" definido como NSDate? y está indexado. He usado casi el código exacto para ti y funciona muy bien. Creo que es mejor que usar un tipo –