Sto cercando di trovare la data più vecchia in un determinato attributo in Dati principali. Ho trovato an example in the Core Data Programming Guide che pretende di fare esattamente questo, ma continuo a ricevere un errore selezionato non riconosciuto quando lo eseguo.Dati principali: tentativo di trovare la data minima per un attributo in un'entità
Il mio codice (con modifiche solo minime dall'esempio di 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];
e l'errore:
-[NSCalendarDate count]: unrecognized selector sent to instance ...
che è strano dato che 1) NSCalendarDate è deprecato e 2) I' sicuramente non sto chiamando il conto.
Qualsiasi aiuto sarebbe più apprezzato!
È "startedAt" Definito come NSDate? ed è indicizzato. Ho usato quasi il codice esatto per te e funziona benissimo. Penso che sia meglio che usare un ordinamento –